Kids With the Greatest Number of Candies
给一个数组和一个数, 问这个数组中那些数和数组中最大数的差小于这个数.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Solution { public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) { List<Boolean> res = new ArrayList<>(); int max = 0; for(int i : candies) { max = Math.max(max, i); } for(int i : candies) { if(max - i <= extraCandies){ res.add(true); } else{ res.add(false); } } return res; } } |