# LeetCode:House Robber

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.

C++代码：

class Solution {
public:
int rob(vector<int>& nums) {
int n = nums.size();
if(n == 0)
return 0;
else if(n == 1)
return nums[0];
else{
vector<int> maxn(n,0);
maxn[0] = nums[0];
maxn[1] = max(nums[0],nums[1]);
for(int i = 2;i < n;++i)
{
maxn[i] = max(maxn[i - 2] + nums[i],maxn[i - 1]);
}
return maxn[n - 1];
}
}
};

#### Leetcode 198: House Robber

2015-04-01 02:51:09

#### leetcode之House Robber(打家劫舍)

2015-11-05 20:24:01

#### leetcode 213 : House Robber II

2015-05-21 07:36:47

#### [leetcode] 337. House Robber III

2016-03-12 20:20:56

#### leetcode 198 House Robber C++

2016-05-28 19:45:09

#### 198. House Robber Leetcode Python

2015-03-31 22:28:07

#### leetcode 198 c++. House Robber

2016-12-11 13:26:39

#### LeetCode213:House Robber II

2015-06-13 11:14:36

#### LeetCode337. House Robber III

2016-03-23 20:34:40

#### [leetcode-337]House Robber III(java)

2016-03-27 22:19:41