본문 바로가기
JAVA

[리트코드/자바] 1431.kids with the greatest number of candies

by 동백05 2023. 7. 17.

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;
    }
}

댓글