leetcode 198 House Robber
来源:互联网 发布:淘宝竹筒粽子的竹筒 编辑:程序博客网 时间:2024/06/08 10:51
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.
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases. Also thanks to @ts for adding additional test cases.
Subscribe to see which companies asked this question
class Solution {public: int rob(vector<int>& nums) { int len = nums.size(); if(len==0) return 0; //vector<vector<int>> dp(len, vector<int>(2,0)); vector<int> dp(2, 0); //dp[0][0] = 0; //dp[0][1] = nums[0]; dp[0] = 0; dp[1] = nums[0]; for(int i = 1; i < len; i++) { //dp[i][0] = max(dp[i-1][1], dp[i-1][0]); int temp = dp[0]; dp[0] = max(dp[1], dp[0]); //dp[i][1] = dp[i-1][0]+nums[i]; dp[1] = temp+nums[i]; } //return dp[len-1][0] > dp[len-1][1] ? dp[len-1][0] : dp[len-1][1]; return dp[0] > dp[1] ? dp[0] : dp[1]; }};
- Leetcode 198: House Robber
- leetcode-198 House Robber
- [LeetCode 198]House Robber
- House Robber - LeetCode 198
- leetcode 198 House Robber
- leetCode #198 House Robber
- LeetCode 198-House Robber
- Leetcode[198]-House Robber
- 【Leetcode】House Robber #198
- Leetcode 198 House Robber
- leetcode 198:House Robber
- House Robber (leetcode 198)
- 【LeetCode】198:House Robber
- leetcode[198]:House Robber
- leetcode-198-House Robber
- leetcode 198: House Robber
- [LeetCode 198]House Robber
- Leetcode# 198 House Robber
- 个人记录1-解决listview异步加载图片错位,滑动listview错乱抖动的问题
- 对于golang的goroutine并发处理任务时的理解
- String 初始化 equals ==
- bat 查看apk信息
- 文章出自http://blog.csdn.net/loongggdroid/article/details/17616509
- leetcode 198 House Robber
- Eclipse的使用小技巧和快捷键演示
- 算法竞赛入门经典(第2版)习题1-2详解
- 反思,今天总体感觉事情很简单,但项目比较多,没有掌握住很好的技巧,所以感觉很混乱
- 安卓中计算 TextView 的宽高、打点
- iOS_逆向_使用class dump导出头文件
- Java正则表达式
- 直线分割平面问题(数学归纳法)
- Java构造函数