https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
Kids With the Greatest Number of Candies - LeetCode
Can you solve this real interview question? Kids With the Greatest Number of Candies - There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandie
leetcode.com
import java.util.*;
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int[] findMax=candies.clone();
int kids=candies.length;
List<Boolean> answer=new ArrayList<Boolean>();
Arrays.sort(findMax);
int max=findMax[kids-1];
for(int i=0;i<kids;i++){
if((candies[i]+extraCandies)>=max){
answer.add(true);
}else{
answer.add(false);
}
}
return answer;
}
}
'JAVA' 카테고리의 다른 글
[리트코드/자바] 1732.find the highest altitude (0) | 2023.07.20 |
---|---|
[백준/자바] 11399번: ATM (0) | 2023.07.18 |
[리트코드/자바] Merge Strings Alternately (0) | 2023.07.16 |
[프로그래머스/자바] Lv.0 삼각형의 완성조건(2) (0) | 2023.07.14 |
[백준/자바] 1253번: 좋다 (0) | 2023.07.11 |
댓글