Skip to content

Commit 1521278

Browse files
add 2928
1 parent 90a6a7f commit 1521278

File tree

3 files changed

+55
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+55
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
77
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
88
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
9+
| 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2928.java) | | Easy |
910
| 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2923.java) | | Easy |
1011
| 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2917.java) | | Easy |
1112
| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2913.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2928 {
7+
public static class Solution1 {
8+
public int distributeCandies(int n, int limit) {
9+
List<List<Integer>> candidates = new ArrayList<>();
10+
for (int maxCandyForOneChild = limit; maxCandyForOneChild >= 0; maxCandyForOneChild--) {
11+
int remainingCandies = n - maxCandyForOneChild;
12+
for (int i = 0; i <= remainingCandies; i++) {
13+
List<Integer> candidate = new ArrayList();
14+
candidate.add(maxCandyForOneChild);
15+
if (remainingCandies - i <= limit && i <= limit) {
16+
candidate.add(i);
17+
candidate.add(remainingCandies - i);
18+
}
19+
if (candidate.size() == 3) {
20+
candidates.add(candidate);
21+
}
22+
}
23+
}
24+
return candidates.size();
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2928;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2928Test {
10+
private static _2928.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2928.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(3, solution1.distributeCandies(5, 2));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(10, solution1.distributeCandies(3, 3));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)