LeetCode

程式碼
class Solution {
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        int max = max(candies);
        List<Boolean> result = new ArrayList<>();
        for (int i = 0; i < candies.length; i++) {
            result.add(candies[i] + extraCandies >= max);
        }
        return result;
    }
    
    private int max(int[] candies) {
        int max = 0;
        for ( int i = 0; i < candies.length; i++ ) {
            if (max < candies[i]) {
                max = candies[i];
            }
        }
        return max;
    }
}

接下來看什麼

上一篇 / 下一篇
上一篇:leetcode - Shuffle the Array 下一篇:LeetCode - Kids With the Greatest Number of Candies
延伸閱讀
訂閱 RSS: 總經 · 技術