Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb3f67f

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /