题解 | #打家劫舍(一)#
打家劫舍(一)
https://www.nowcoder.com/practice/c5fbf7325fbd4c0ea3d0c3ea6bc6cc79
class Solution: def rob(self, nums:List[int]) -> int: n=len(nums) dp=[0]*(n+1) dp[1]=nums[0] for i in range(2,n+1): dp[i]=max(dp[i-1],nums[i-1]+dp[i-2]) return dp[n]