문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
사탕과 함께 n명의 어린이가 있다. 정수 배열 candies, candies[i]는 i번째 아이가 가지고 있는 사탕의 개수와 추가 사탕의 개수인 정수 extraCandies가 주어진다.
길이가 n인 boolean 배열 result를 반환해라. result[i]는 i번째 아이에게 모든 추가 사탕은 준 후에 그 아이가 모든 아이들 중에서 가장 많은 사탕을 가지게 되면 true, 그렇지 않다면 false이다.
#1
Input: candies = [2, 3, 5, 1, 3], extraCandies = 3
Output: [true, true, true, false, true]
#2
Input: candies = [4, 2, 1, 1, 2], extraCnadies = 1
Output: [true, false, false, false, false]
#3
Input: candies = [12, 1, 12], extraCandies = 10
Output: [true, false, true]
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
List<Boolean> result = new ArrayList<>();
int max = 0;
for(int candy : candies){
max = Math.max(max, candy);
}
for(int candy : candies){
result.add(candy + extraCandies >= max);
}
return result;
}
}