Skip to content

Commit

Permalink
xiao commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 19, 2022
1 parent 24447a9 commit 2592f99
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions leetcode_practice/740_leetcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def deleteAndEarn(self, nums: List[int]) -> int:
maxVal = max(nums)
total = [0] * (maxVal + 1)
for val in nums:
total[val] += val # 索引对应nums的值,值对应nums里值的和
# 每个房间有一定现金
def rob(nums: List[int]) -> int:
dp = [0] * len(nums)
dp[0] = nums[0]
dp[1] = max(nums[0], nums[1])
for i in range(2, len(nums)):
dp[i] = max(dp[i-2]+nums[i], dp[i-1])
return dp[-1]

return rob(total)

0 comments on commit 2592f99

Please sign in to comment.