[코테 풀이] Kids With the Greatest Number of Candies

시내·2024년 6월 11일
0

Q_1431) Kids With the Greatest Number of Candies

출처 : https://leetcode.com/problems/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 extraCandies, denoting the number of extra candies that you have.

Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.

Note that multiple kids can have the greatest number of candies.

class Solution {
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies){
        List<Boolean> booleans = new ArrayList<>();
        boolean chk = false;
        for (int c = 0; c < candies.length; c++) {
            int updated = candies[c] + extraCandies;
            System.out.println(updated);
            for (int d = 0; d < candies.length; d++) {
                if (updated < candies[d]) {
                    booleans.add(false);
                    break;
                } else if (d == candies.length - 1) booleans.add(true);

            }
        }
        return booleans;
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글