# 213. House Robber II

After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, the security system for these houses remain the same as for those in the previous street.

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 @Freezen for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

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

}

//下面就是House Robber的解答，用a表示第i-2次，b表示i-1次，省去了开一个数组保存的麻烦。
int rob(vector<int>&nums, int start, int end)
{
int a=0,b=0;
for(int i=start;i<end;i++)
{
int m=max(b,a+nums[i]);
a=b;
b=m;
}
return b;
}
};

#### LeetCode213:House Robber II

2015-06-13 11:14:36

#### leetcode 213 : House Robber II

2015-05-21 07:36:47

#### Leetcode 213 House Robber II 抢劫最大金额

2015-08-19 23:38:10

#### 【Leetcode】213. House Robber II 【动态规划】

2016-07-24 00:25:26

#### 198. House Robber [easy] (Python)

2016-06-01 14:39:22

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

2015-11-05 20:24:01

#### 【leetCode】House Robber II python实现

2016-06-19 21:25:46

#### LeetCode - 213. House Robber II

2016-07-10 09:22:18

#### 213. House Robber II**

2017-02-01 13:53:24

#### Leetcode 198: House Robber

2015-04-01 02:51:09