class Solution:
def rob(self, nums: list[int]) -> int:
def _rob(start: int, stop: int):
a, b = 0, 0
for i in range(start, stop):
a, b = b, max(a + nums[i], b)
return b
return max(_rob(0, len(nums) - 1), _rob(1, len(nums)))
213. House Robber II - LeetCode
ยท One min read