Skip to content

740 delete and earn

740. Delete and Earn

题目: https://leetcode.com/problems/delete-and-earn/

难度:

Medium

class Solution(object):
    def deleteAndEarn(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        dp = [0] * 10001
        for num in nums:
            dp[num] += num
        for i in range(2, 10001):
            dp[i] = max(dp[i]+dp[i-2], dp[i-1])
        return dp[-1]

我们一直在努力

apachecn/AiLearning

【布客】中文翻译组