[Array / String, Easy] Kids With the Greatest Number of Candies

송재호·2025년 3월 9일
0

https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/description/?envType=study-plan-v2&envId=leetcode-75

cnadies중 max값을 찾아놓고 그것보다 큰지 작은지만 알아보면 된다.

class Solution {
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> answer = new ArrayList<>();

        int max = Integer.MIN_VALUE;
        for (int candy : candies) {
            max = Math.max(max, candy);
        }

        for (int candy : candies) {
            answer.add(candy + extraCandies >= max);
        }

        return answer;
    }
}
profile
식지 않는 감자

0개의 댓글