Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

1431. Kids With the Greatest Number of Candies

Posted on 2020-07-27 | Edited on 2021-01-22

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;
}
}
<1…383940…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%