1431. Kids With the Greatest Number of Candies

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
int n = candies.size();
int mx = *max_element(candies.begin(), candies.end());
vector<bool> ret(n, false);
for(int i =0;i<n;++i)
{
ret[i] = candies[i]+extraCandies >= mx? true:false;
}
return ret;
}
};

analysis

  • time complexity O(n)
  • space complexity O(n)