740. Delete and Earn
Medium
You are given an integer array nums
. You want to maximize the number of points you get by performing the following operation any number of times:
Pick any
nums[i]
and delete it to earnnums[i]
points. Afterwards, you must delete every element equal tonums[i] - 1
and every element equal tonums[i] + 1
.
Return the maximum number of points you can earn by applying the above operation some number of times.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 2 * 104
1 <= nums[i] <= 104
解題
這題 DP 的技巧和 198. House Robber 差不多。
Runtime: 7 ms, faster than 95.31%
Memory Usage: 5.9 MB, less than 39.58%
Last updated