###### Middle-题目58：213. House Robber II

Note: This is an extension of House Robber.

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.

Easy-题目26，但是现在房子围成了环形，仍然求最大利益。

int rob(int* nums, int numsSize) {
if(numsSize==0)
return 0;
else if(numsSize==1)
return nums[0];
else if(numsSize==2)
return nums[0]>nums[1]?nums[0]:nums[1];
else
return max(rob1(nums,numsSize-1),rob1(nums+1,numsSize-1));
}
int max(int a,int b) {
return a>b?a:b;
}
int rob1(int* nums, int numsSize) {
if(numsSize==0)
return 0;
if(numsSize==1)
return nums[0];
else if(numsSize==2)
return nums[0]>nums[1]?nums[0]:nums[1];
else
{
int i;
int dp1,dp2,dp;

dp1=nums[0];
dp2=nums[0]>nums[1]?nums[0]:nums[1];
for(i=2;i<numsSize;i++)
{
dp=dp2>dp1+nums[i]?dp2:dp1+nums[i];
dp1=dp2;
dp2=dp;
}
return dp;
}
}

1ms，众数100%
Cmershen的碎碎念：

#### 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

#### leetcode 213 c++. House Robber II

2016-12-11 15:00:45

#### [leetcode-213]House Robber II(java)

2015-08-28 10:51:44

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

2016-06-01 14:39:22

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

2015-11-05 20:24:01

#### LeetCode_198. House Robber_动态规划

2016-01-21 12:45:01

#### 【LeetCode】213. House Robber II

2016-10-17 15:05:47

## 不良信息举报

Middle-题目58：213. House Robber II