198. House Robber
来源:互联网 发布:linux 重置网络配置 编辑:程序博客网 时间:2024/06/10 02:47
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.
1、把之前的currentNo, 和 currentRob都变成preNo,preRob。
2、如果这间房子不抢,currentNo是preNo,preRob较大的一个。
3、如果抢这间房子,currentRob是preNo加上这间房子的金额。
代码如下:
public class Solution { public int rob(int[] nums) { int currRob = 0, currNo = 0; for (int num:nums) { int preNo = currNo; int preRob = currRob; currNo = Math.max(preNo, preRob); currRob = preNo + num; } return Math.max(currNo, currRob); }}
- 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
- STM32F103的IAP中Bootloader中断以及App程序不能进入中断的问题解决方法。
- 最大连续和的四种解法
- Number Complement
- 对于SPFA的优化
- 初识Java的接口和抽象类
- 198. House Robber
- 1034: [ZJOI2008]泡泡堂BNB
- OSRefTable 用法
- Java:Map与HashMap,Hashtable,HashSet比较
- 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
- centos 7 下安装tomcat 8.5.11
- 2761: [JLOI2011]不重复数字
- JZOJ-senior-3899. 【NOIP2014模拟】逻辑的连通性
- weex学习笔记-Couldn't find preset "es2015" relative to directory