Leetcode 740. Delete and Earn
2019-01-31 本文已影响1人
SnailTyan
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Delete and Earn2. 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];
}
};