---
# System prepended metadata

title: 0740. Delete and Earn
tags: [Dynamic Programming]

---

Link: https://leetcode.com/problems/delete-and-earn/description/
## 思路
桶排序+基本型I DP
## Code
```python=
class Solution:
    def deleteAndEarn(self, nums: List[int]) -> int:
        valSum = [0]*10001
        for num in nums:
            valSum[num] += num
        take, skip = 0, 0
        for val in valSum:
            oldTake = take
            take = skip+val
            skip = max(skip, oldTake)
        return max(take, skip)
```
