198. House Robber
来源:互联网 发布:连接香港网络 编辑:程序博客网 时间:2024/06/16 11:27
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.
class Solution {public: int rob(vector<int>& nums) { int n=nums.size(); if(n==0) return 0; if(n==1) return nums[0]; if(n==2) return nums[0]>nums[1]?nums[0]:nums[1]; vector<int> count(n,0); count[0]=nums[0]; count[1]=(nums[0]>nums[1]?nums[0]:nums[1]); for(int i=2;i<n;i++) { if(nums[i]+count[i-2]>count[i-1]) count[i]=nums[i]+count[i-2]; else count[i]=count[i-1]; } return count[n-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
- SpringBoot学习 (二)— 依赖注入
- linux 强行杀掉进程
- 面试题(数据库2)
- ubuntu centos RedHat 下载地址
- Android service:Binder
- 198. House Robber
- 设计模式——简单工厂模式
- Javascript数据结构算法之栈(进制转换,阶乘,后缀表达式,括号匹配)
- sh 脚本打印log
- 等差数列应用——控制台输出沙漏
- Gym 101243 (2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest)
- test
- MySQL5.7 启动报错:initialize specified but the data directory has files in it. Aborting.
- Android虚拟机——Dalvik/ART