【LeetCode】1798. 你能构造出连续值的最大数目

  • 思路很巧妙
class Solution {
public:
    int getMaximumConsecutive(vector<int>& coins) {
        sort(coins.begin(),coins.end());
        int x = 0;
        for(int y:coins)
        {
            if(y > x + 1) break;
            x = x + y;
        }
        return x + 1;
    }
};
posted @ 2023-02-04 15:59  小超不挑食  阅读(14)  评论(0编辑  收藏  举报