1431_KidsWiththeGreatestNumberofCandies - a920604a/leetcode GitHub Wiki


categories: leetcode comments: false tags: null title: 1431. Kids With the Greatest Number of Candies

solution

class Solution {
public:
    vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
        vector<bool> ret;
        int n = candies.size(), mx =0;
        for(int c:candies) mx = max(mx, c);
        for(int c:candies) ret.push_back( (c+extraCandies)>=mx?true:false );
        return ret;
    }
};

analysis

  • time complexity O(n)
  • space complexity O(n)
⚠️ **GitHub.com Fallback** ⚠️