House Robber II LeetCode solution in Python

1
class Solution(object):
2
def rob(self, nums):
3
"""
4
:type nums: List[int]
5
:rtype: int
6
"""
7
if len(nums) == 1:
8
return nums[0]
9

10
def helper(nums):
11
one, two = 0, 0
12
for i in nums:
13
temp = max(i + one, two)
14
one = two
15
two = temp
16
return two
17

18
return max(helper(nums[:-1]), helper(nums[1:]))

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0