Skip to content

Commit eb3f67f

Browse files
committed
added solution in java: 1431. Kids With the Greatest Number of Candies
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent 1ea07e4 commit eb3f67f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
class Solution {
5+
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
6+
int max = 0;
7+
8+
for (int candy : candies) {
9+
if (candy > max) {
10+
max = candy;
11+
}
12+
}
13+
14+
List<Boolean> res = new ArrayList<>();
15+
16+
for (int i = 0; i < candies.length; i++) {
17+
if (candies[i] + extraCandies >= max) {
18+
res.add(true);
19+
} else {
20+
res.add(false);
21+
}
22+
}
23+
24+
return res;
25+
}
26+
}

0 commit comments

Comments
 (0)