코딩테스트

[leetcode] 1431. Kids With the Greatest Number of Candies

nayoon 2024. 5. 18. 09:44

링크

/**
    
    first of all, know the greatest number of integer array candies 
    using for iterator, give extraCandies and then judge..? their number

 */
class Solution {
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        int max = 0;
        for(int i = 0; i < candies.length; i++) {
            if (max < candies[i]) {
                max = candies[i];
            }
        }

        List<Boolean> result = new ArrayList<>();
        for(int i = 0; i < candies.length; i++) {
            if (candies[i] + extraCandies >= max) {
                result.add(true);
            }
            else {
                result.add(false);
            }
        }
        return result;
    }
}