class Solution {
public int rob(int[] nums) {
if(nums.length==0)return 0;
int[] memo=new int[nums.length+1];
memo[0]=0;
memo[1]=nums[0];
for(int i=2;i<=nums.length;i++){
memo[i]=Math.max(memo[i-2]+nums[i-1],memo[i-1]);
}
return memo[nums.length];
}
}
[leetcode]198. House Robber
猜你喜欢
转载自blog.csdn.net/weixin_36869329/article/details/84987833
今日推荐
周排行