-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2682.java
35 lines (33 loc) · 920 Bytes
/
_2682.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.fishercoder.solutions.thirdthousand;
import java.util.HashSet;
import java.util.Set;
public class _2682 {
public static class Solution1 {
public int[] circularGameLosers(int n, int k) {
if (n == 1) {
return new int[0];
}
Set<Integer> met = new HashSet<>();
int i = 1;
int ball = 1;
while (met.add(ball)) {
ball += (i * k) % n;
if (ball > n) {
ball %= n;
}
i++;
}
if (n == met.size()) {
return new int[0];
}
int[] ans = new int[n - met.size()];
int q = 0;
for (int j = 1; j <= n; j++) {
if (!met.contains(j)) {
ans[q++] = j;
}
}
return ans;
}
}
}