文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Leetcode 740. Delete and Earn

2. Solution

class Solution {
public:
    int deleteAndEarn(vector<int>& nums) {
    	int points = 0;
        int point[10001] = {0};
        for(int num : nums) {
        	point[num] += num;
        }
        for(int i = 2; i < 10001; i++) {
        	point[i] = max(point[i - 2] + point[i], point[i - 1]);
        }
        return point[10000];
    }
};

Reference

  1. https://leetcode.com/problems/delete-and-earn/description/

相关文章: