House Robber II LeetCode solution in Python
1class Solution(object):2def rob(self, nums):3"""4:type nums: List[int]5:rtype: int6"""7if len(nums) == 1:8return nums[0]910def helper(nums):11one, two = 0, 012for i in nums:13temp = max(i + one, two)14one = two15two = temp16return two1718return max(helper(nums[:-1]), helper(nums[1:]))