日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > php教程 > [LeetCode] House Robber

[LeetCode] House Robber

來源:程序員人生   發(fā)布時間:2015-07-06 10:27:17 閱讀次數(shù):2501次

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

解題思路

動態(tài)計劃
狀態(tài)轉移方程:f[i] =max(f[i⑴], f[i⑵]+c[i])
f[i]表示進入第i+1個房間時所得到的最大財富。
為了節(jié)省空間,只是用3個變量prepre, pre, cur便可。

實現(xiàn)代碼1

//Runtime:2ms class Solution { public: int rob(vector<int>& nums) { int len = nums.size(); if (len == 0) return 0; if (len == 1) return nums[0]; if (len == 2) return max(nums[0], nums[1]); int prepre = nums[0]; int pre = max(nums[0], nums[1]); int cur; for (int i = 2; i < len; i++) { cur = max(pre, prepre + nums[i]); prepre = pre; pre = cur; } return cur; } };

實現(xiàn)代碼2

# Runtime:76ms class Solution: # @param {integer[]} nums # @return {integer} def rob(self, nums): size = len(nums) if size == 0: return 0 elif size == 1: return nums[0] elif size == 2: return max(nums[0], nums[1]) prepre = nums[0] pre = max(nums[0], nums[1]) for i in range(2, size): cur = max(pre, prepre + nums[i]) prepre = pre pre = cur return cur
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日韩精品免费在线观看 | 精品国产乱码久久久久久久软件 | 亚洲综合区 | 精品一区二区久久 | 网友自拍第一页 | 成年人在线观看 | 爱情岛论坛av | 国产色网 | 国产成人精品一区二区三区视频 | 99re在线观看 | 久久精品1| 亚洲视频免费观看 | 全免一级毛片 | 在线国产视频 | 可以免费看的毛片 | 欧美成人精精品一区二区频 | 男女av| 国内a∨免费播放 | 成人6969www免费视频 | 欧美一区二区三区在线视频 | 999久久久精品视频 国产第91页 | 国产第二区 | 国产又色又爽又黄又免费 | 日韩在线观看视频免费 | 国产成人精品视频 | 国产在线精品自拍 | 精品久草| 国产欧美精品 | 国产永久免费 | 亚洲精彩免费视频 | 成人国产综合 | 色婷婷精品国产一区二区三区 | 一级毛片观看 | 成年人在线免费观看 | 91午夜在线| 中文字幕久久久 | 男女上床网站 | 精品粉嫩aⅴ一区二区三区四区 | 一级黄色毛片 | 国产精品电影网 | 精品日韩一区二区三区 |