# 1 题目描述

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.

# 3 源代码

package com.larry.easy;

public class HouseRobber {
public int rob(int[] nums) {
//max表示第i个房的最大收益
int len = nums.length;
int max[] = new int[len];

if(len == 0) return 0;
else if(len == 1) return nums[0];
else{
max[0] = nums[0];
if(nums[0] >= nums[1]) max[1] = nums[0];
else max[1] = nums[1];
for(int i = 2; i < len; i++)
max[i] = Math.max(max[i-2] + nums[i], max[i-1]);
}
return max[len-1];
}
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：House Robber 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)