LeetCode 第 25 场双周赛 5384. 拥有最多糖果的孩子

题目链接

在这里插入图片描述在这里插入图片描述

  • 这一题白给,只不过当时写的的时候,代码还是过于冗杂了,其实应该很短就能写完,这一块主要是自己的临场能力还不太行吧,而且吐槽一下当时的评测机,第一题愣是转了大概一分钟才过了
    代码:
class Solution {
    
    
public:
    vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
    
    
        vector<int> temp(candies.size());
        vector<bool> ans;
        temp=candies;
        sort(temp.begin(),temp.end());
        int m=temp[candies.size()-1];
        for(int i=0;i<candies.size();i++)
        {
    
    
            if(candies[i]+extraCandies>=m)
                ans.push_back(true);
            else
                  ans.push_back(false);   
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_43663263/article/details/105902686
今日推荐