simple python solution


  • 0
    W
    class Solution(object):
        def rob(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            tmp=[0,0]
            for i in range(len(nums)):
                if i%2==0: tmp[0]=max(tmp[0]+nums[i],tmp[1])
                else:tmp[1]=max(tmp[1]+nums[i],tmp[0])
            return max(tmp)
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.