-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc_1431.java
More file actions
48 lines (34 loc) · 1 KB
/
Lc_1431.java
File metadata and controls
48 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Lc- 1431. Kids With the Greatest Number of Candies
import java.util.*;
public class Lc_1431 {
static int maxElement(int[] candies){
int max = Integer.MIN_VALUE;
for (int candy : candies) {
if (candy > max) {
max = candy;
}
}
return max;
}
static List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
List<Boolean> res = new ArrayList<>();
int max = maxElement(candies);
for (int candy : candies) {
if ((candy + extraCandies) >= max) {
res.add(true);
} else {
res.add(false);
}
}
return res;
}
public static void main(String[] args) {
int[] candy = new int[]{2, 3, 6, 1, 3};
int extraCandies = 3;
List<Boolean> res = new ArrayList<>();
res = kidsWithCandies(candy, extraCandies);
for (boolean r : res) {
System.out.println(r);
}
}
}