LC213 - House Robber II
Problem
Solution
Dynamic Programming
def rob(self, nums: List[int]) -> int:
# Handle edge case of when ends are adjacent and if subarray empty
return max(nums[0], self.robMax(nums[1:]), self.robMax(nums[:-1]))
def robMax(self, nums):
rob1 = 0
rob2 = 0
for n in nums:
maxRob = max(n + rob1, rob2)
rob1 = rob2
rob2 = maxRob
return rob2Last updated