CODE

class Solution:
    def rob(self, nums: List[int]) -> int:
        def helper(nums):
            rob1, rob2 = 0, 0
            for n in nums:
                temp = max(n + rob1, rob2)
                rob1 = rob2
                rob2 = temp
            return rob2
        # MAX of If there is only one house; nums[0] else skip first and skip last
        return max(nums[0], helper(nums[1:]), helper(nums[:-1]))
        
        

Last updated