Why doesn't this work ??


  • 0
    class Solution(object):
        robbingProfits={}
        def rob(self, nums):
            if nums==None or nums==[]:
                return 0
            l=len(nums)
            if l in self.robbingProfits.keys():
                pass
            elif l==1:
                self.robbingProfits[l]=nums[0]
            elif l==2:
                self.robbingProfits[l]=max(nums)
            else:
                self.robbingProfits[l]=max(self.rob(nums[:l-1]),nums[l-1]+self.rob(nums[:l-2]))
            return self.robbingProfits[l]
    

Log in to reply
 

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