Skip to content

Commit cc63f52

Browse files
add 2682
1 parent f62bb60 commit cc63f52

File tree

3 files changed

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

3 files changed

+77
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2706.java) | | Easy |
1818
| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2697.java) | | Easy |
1919
| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2696.java) | | Easy |
20+
| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2682.java) | | Easy |
2021
| 2673 | [Make Costs of Paths Equal in a Binary Tree](https://leetcode.com/problems/make-costs-of-paths-equal-in-a-binary-tree/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2673.java) | | Medium |Tree, DFS, Greedy
2122
| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2678.java) | | Easy |
2223
| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2670.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2682 {
7+
public static class Solution1 {
8+
public int[] circularGameLosers(int n, int k) {
9+
if (n == 1) {
10+
return new int[0];
11+
}
12+
Set<Integer> met = new HashSet<>();
13+
int i = 1;
14+
int ball = 1;
15+
while (met.add(ball)) {
16+
ball += (i * k) % n;
17+
if (ball > n) {
18+
ball %= n;
19+
}
20+
i++;
21+
}
22+
if (n == met.size()) {
23+
return new int[0];
24+
}
25+
int[] ans = new int[n - met.size()];
26+
int q = 0;
27+
for (int j = 1; j <= n; j++) {
28+
if (!met.contains(j)) {
29+
ans[q++] = j;
30+
}
31+
}
32+
return ans;
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2682;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
8+
9+
public class _2682Test {
10+
private static _2682.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2682.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertArrayEquals(new int[]{4, 5}, solution1.circularGameLosers(5, 2));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertArrayEquals(new int[]{}, solution1.circularGameLosers(2, 1));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertArrayEquals(new int[]{3}, solution1.circularGameLosers(3, 1));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertArrayEquals(new int[]{2}, solution1.circularGameLosers(3, 2));
35+
}
36+
37+
@Test
38+
public void test5() {
39+
assertArrayEquals(new int[]{2, 3}, solution1.circularGameLosers(5, 3));
40+
}
41+
}

0 commit comments

Comments
 (0)