[LeetCode]House Robber
来源:互联网 发布:matlab统计 知乎 编辑:程序博客网 时间:2024/05/16 14:35
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.
public class Solution { public int rob(int[] num) { if(num==null||num.length==0) return 0; int include = 0; int exclude = 0; for(int i=0;i<num.length;i++){ int tmp = include; include = exclude+num[i]; exclude = Math.max(tmp, exclude); } return Math.max(include, exclude); }}
0 0
- 【dp】Leetcode House Robber&& House Robber II
- 【leetcode】House Robber && House Robber II
- LeetCode --- House Robber & House Robber II
- LeetCode OJ House Robber
- Leetcode: House Robber
- Leetcode 198: House Robber
- House Robber - LeetCode
- LeetCode 之 House Robber
- leetcode--House Robber
- [leetcode]47 House Robber
- [LeetCode] House Robber
- LeetCode :House Robber
- [leetcode] House Robber
- [leetcode]House Robber
- [LeetCode]198.House Robber
- LeetCode House Robber题解
- leetcode:House Robber
- [LeetCode]House Robber
- 第六周阅读程序
- 使用VideoView播放视频
- (5-2)Writable源码分析
- Android开源项目 分类 值得学习
- Android4.4制作自有SDK探析
- [LeetCode]House Robber
- 为什么构造函数不能声明为虚函数,析构函数可以
- 第六届南桥杯A组Java第二题 星系炸弹
- android常用控件属性(中文)
- 如何更加巧妙地解决所面对的问题
- Q4: N元一次方程组(矩阵)
- zeromq samples version
- iOS开发的经典博客和文章汇总【原创】
- Servlet中FORWARD和redirect的区别