Your runtime beats 98.93% of python submissions.


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

Log in to reply
 

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