Skip to content

Commit c7ce8dd

Browse files
authored
Create 1823. Find the Winner of the Circular Game
1 parent a94e2c1 commit c7ce8dd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int findTheWinner(int n, int k) {
4+
queue<int> q;
5+
for(int i=1;i<=n;++i){q.push(i);}
6+
while(q.size()>=2){
7+
for(int i=0;i<k-1;++i){
8+
int f = q.front();
9+
q.pop();
10+
q.push(f);
11+
}
12+
q.pop();
13+
}
14+
return q.front();
15+
}
16+
};

0 commit comments

Comments
 (0)