198. House Robber
来源:互联网 发布:交叉网络外部性 编辑:程序博客网 时间:2024/05/22 00:56
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.
int rob(vector<int>& nums) { if (nums.size() == 0)return 0; if (nums.size() == 1)return nums[1]; vector<int> dp(nums.size(), 0); dp[0] = nums[0], dp[1] = max(nums[0], nums[1]); for (int i = 1; i < nums.size(); i++){ dp[i] = max(dp[i - 1], dp[i - 2] + nums[i]); } return dp[nums.size() - 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
- 三维重建面试3:如何形象地理解四元数
- 步步高告诉你如何获客增长:4种数字化驱动案例
- Android service解析与使用实例
- Webpack项目构建
- sql如何部分distinct查询?
- 198. House Robber
- 数据结构---线性表---链性存
- 2017-PayPal商家集成常见技术问题-官方整理
- 2017-06-19 第一天
- git 命令大全
- 图形理解 LSTM 网络
- 改变eclipse的主题,使用IDEA的黑色主题
- 我所理解的RxJava——上手其实很简单(一) 144 作者 Weavey 关注 2016.08.27 03:30* 字数 2789 阅读 45458评论 60喜欢 289 前言 相信各位看官对R
- SearchView的使用说明