1823. Find the Winner of the Circular Game
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public int findTheWinner(int n, int k) { if (n == 1) { return 1; }
int tmp = (findTheWinner(n - 1, k) + k) % n; return tmp == 0 ? n : tmp; } }
|
References
1823. Find the Winner of the Circular Game
约瑟夫环问题的三种解法讲解