Skip to content

Commit 1e29e3e

Browse files
committed
Added Find the Losers of the Circular Game.java
1 parent f9e9563 commit 1e29e3e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int[] circularGameLosers(int n, int k) {
3+
Set<Integer> set = new HashSet<>();
4+
int player = 1;
5+
int multiple = k;
6+
while (set.add(player)) {
7+
player = (player + k) % n;
8+
player = player == 0 ? n : player;
9+
k += multiple;
10+
}
11+
int[] result = new int[n - set.size()];
12+
for (int i = 1, j = 0; i <= n; i++) {
13+
if (!set.contains(i)) {
14+
result[j++] = i;
15+
}
16+
}
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)