Leetcode

Leetcode 740. Delete and Earn

2019-01-31  本文已影响1人  SnailTyan

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

1. Description

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/
上一篇下一篇

猜你喜欢

热点阅读