Skip to content

Commit fde94d6

Browse files
add 1431
1 parent 589a1a2 commit fde94d6

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1431|[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1431.java) | |Easy|Array|
1112
|1423|[Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1423.java) | |Medium|Array, DP, Sliding Window|
1213
|1422|[Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1422.java) | |Easy|String|
1314
|1418|[Display Table of Food Orders in a Restaurant](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1418.java) | |Medium|HashTable|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _1431 {
7+
public static class Solution1 {
8+
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
9+
int max = 0;
10+
for (int i : candies) {
11+
max = Math.max(max, i);
12+
}
13+
List<Boolean> result = new ArrayList<>();
14+
for (int i = 0; i < candies.length; i++) {
15+
if (candies[i] + extraCandies >= max) {
16+
result.add(true);
17+
} else {
18+
result.add(false);
19+
}
20+
}
21+
return result;
22+
}
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1431;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static junit.framework.TestCase.assertEquals;
10+
11+
public class _1431Test {
12+
private static _1431.Solution1 solution1;
13+
private static int[] candies;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _1431.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
candies = new int[]{2, 3, 5, 1, 3};
23+
assertEquals(Arrays.asList(true, true, true, false, true), solution1.kidsWithCandies(candies, 3));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)