[LeetCode]198. House Robber
来源:互联网 发布:.net企业门户网站源码 编辑:程序博客网 时间:2024/06/05 22:48
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.
public class Solution { public int rob(int[] nums) { if(nums.length<1) return 0; int maxSoFar=nums[0]; int lastIndex=0; int lastMax=0; //33,1,2,3 for(int i=1; i<nums.length; i++){ if(i-lastIndex==1) { int temp=lastMax+nums[i]; if(temp>maxSoFar){ lastMax=maxSoFar; maxSoFar=temp; lastIndex=i; }else lastMax=temp; } else{ lastMax=maxSoFar; lastIndex=i; maxSoFar+=nums[i]; } } return maxSoFar; }}
Dynamic Programming
阅读全文
0 0
- [LeetCode]198.House Robber
- 【LeetCode】198. House Robber
- 【LeetCode】198.House Robber
- LeetCode 198. House Robber
- [leetcode] 198.House Robber
- [leetcode] 198. House Robber
- LeetCode:198. House Robber
- 198. House Robber LeetCode
- [LeetCode]198. House Robber
- LeetCode || 198. House Robber
- LeetCode-198. House Robber
- [LeetCode]198. House Robber
- 【LeetCode】198. House Robber
- LeetCode#198. House Robber
- LeetCode 198. House Robber
- leetcode 198. House Robber
- LeetCode *** 198. House Robber
- leetcode 198. House Robber
- HDU 6036 Division Game(组合数学+NTT)
- 持续集成
- 多校联合自爆记
- JSP状态管理
- 51nod 1381 硬币游戏
- [LeetCode]198. House Robber
- [LeetCode] 503. Next Greater Element II
- C语言里的注释转换问题 (把C语言的的注释转换成C++的注释)
- SHADOWMAPPING与GLSL
- Spring的相关下载
- HTML基础知识(未完待续)
- CSU 1970:LXX数(数学?)
- 设计模式-21-中介者模式
- 使用epoll模型