198.House Robber
来源:互联网 发布:淘宝网密封胶圈 编辑:程序博客网 时间:2024/06/06 08:40
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.
//http://www.cnblogs.com/ganganloveu/p/4417485.htmlclass Solution {public: int rob(vector<int>& nums) { int numsSize = nums.size(); if(numsSize == 0) return 0; if(numsSize == 1) return nums[0]; vector<int> maxVal(numsSize,0); maxVal[0] = nums[0]; maxVal[1] = max(nums[0],nums[1]); for(int i = 2;i<numsSize;i++) { maxVal[i] = max((maxVal[i - 2] + nums[i]),maxVal[i-1]); } return maxVal[numsSize-1]; }};
1
0 0
- 337. House Robber III+198. House Robber
- 198. House Robber&&213. House Robber II
- 198. House Robber && 213. House Robber II
- [LeetCode]198.House Robber
- 【LeetCode】198. House Robber
- 【LeetCode】198.House Robber
- LeetCode 198. House Robber
- 198.House Robber
- [leetcode] 198.House Robber
- [leetcode] 198. House Robber
- LeetCode:198. House Robber
- 198. House Robber LeetCode
- 198. House Robber
- [LeetCode]198. House Robber
- 198. House Robber
- LeetCode || 198. House Robber
- 198. House Robber
- LeetCode-198. House Robber
- Material UI:非常强大的CSS框架
- EasyUIControl(一个可以简化ui界面的组件库
- 每个Java程序员必备的8个开发工具
- using List
- 带有checkbox的jstree封装
- 198.House Robber
- GC - (一) What Is Garbage Collection?
- 213.House Robber II
- eclipse快捷键
- VS2010编译libtorrent
- 《统计学习方法》笔记(六)--决策树
- 排序算法合集
- 深入理解Spring AOP之二代理对象生成
- 微信分享