美文网首页Leetcode
Leetcode 740. Delete and Earn

Leetcode 740. Delete and Earn

作者: SnailTyan | 来源:发表于2019-01-31 10:58 被阅读1次

    文章作者: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/

    相关文章

      网友评论

        本文标题:Leetcode 740. Delete and Earn

        本文链接:https://www.haomeiwen.com/subject/gorksqtx.html