0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution: def rob(self, nums: List[int]) -> int: d = [0 for _ in range(len(nums))] if len(nums)==1: return nums[0] elif len(nums)==2: return max(nums[0],nums[1]) d[0],d[1] = nums[0],max(nums[0],nums[1]) for i in range(2,len(nums)): d[i] = max(d[i-2]+nums[i],d[i-1]) print(d) return d[len(nums)-1]
|