import java.util.*;
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int max = candies[0];
for (int i = 0; i < candies.length; i++) {
if (candies[i] > max){
max = candies[i];
}
}
ArrayList<Boolean> result = new ArrayList<Boolean>(candies.length);
for (int i = 0; i < candies.length; i++) {
if (candies[i] + extraCandies >= max) {
result.add(true);
} else {
result.add(false);
}
}
return result;
}
}
Runtime: 0 ms
Memory Usage: 39.2 MB
import java.util.*;
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
List<Boolean> kids=new ArrayList<Boolean>();
int maxc=candies[0];
for(int i=0;i<candies.length;i++){
if(candies[i]>maxc){
maxc=candies[i];
}
}
for(int i=0;i < candies.length; i++)
{
if ( candies[i] + extraCandies >= maxc)
{
kids.add(true);
}
else
{
kids.add(false);
}
}
System.gc();
return kids;
}
}
Runtime: 1 ms, faster than 47.50% of Java online submissions for Kids With the Greatest Number of Candies.
Memory Usage: 38.4 MB, less than 99.22% of Java online submissions for Kids With the Greatest Number of Candies.
'Algorithm > LeetCode' 카테고리의 다른 글
[LeetCode] Kids With the Greatest Number of Candies (0) | 2021.06.16 |
---|---|
[LeetCode] Number of Good Pairs (0) | 2021.06.16 |
[LeetCode] Richest Customer Wealth (0) | 2021.06.12 |
[LeetCode] Shuffle the Array (0) | 2021.06.11 |
[LeetCode] Running Sum of 1d Array (0) | 2021.06.08 |