Find the Winner of the Circular Game LeetCode solution in Java

1
class Solution {
2
public int findTheWinner(int n, int k) {
3
// Initialisation of the LinkedList
4
LinkedList<Integer> participants = new LinkedList<>();
5
for (int i = 1; i <= n; i++) {
6
participants.add(i);
7
}
8

9
int lastKilled = 0;
10
// Run the game
11
for (int i = 0; i < n; i++) {
12
for (int j = 0; j < k - 1; j++) {
13
participants.add(participants.poll());
14
}
15
lastKilled = participants.poll();
16
}
17
// Return the last one killed
18
return lastKilled;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0