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.
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.
这道题是House Robber 的拓展题 在第一题的基础上加了一个环 ,意思就是抢了第一家就不能抢最后一家 ,以此来判断
怎么抢劫能使得收益最大化。那今天就来解决这个“环”的问题。我们这里变通一下,如果我们把第一家和最后一家分别去掉,各算一遍能抢的最大值,然后比较两个值取其中较大的一个即为所求。那我们只需参考之前的House Robber 打家劫舍中的解题方法,然后调用两边取较大值,代码如下:
这个算是中等的难度题 按照这个思路码出来发现 运行不了(崩溃中.........)