1431. Kids With the Greatest Number of Candies

LeetCode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Time: O(N)
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int max=Integer.MIN_VALUE;
for(int candy:candies) max=Math.max(candy,max);
List<Boolean> res=new ArrayList<>();
for(int i=0;i<candies.length;i++){
candies[i]=max-candies[i];
if(candies[i]<=extraCandies) res.add(true);
else res.add(false);
}
return res;
}
}
0%