Skip to content

Commit ba543a0

Browse files
authored
Update Solution.js
1 parent 9bdd7f6 commit ba543a0

File tree

1 file changed

+12
-5
lines changed
  • solution/1800-1899/1823.Find the Winner of the Circular Game

1 file changed

+12
-5
lines changed
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
function findTheWinner(n, k) {
2-
if (n === 1) return 1;
3-
const res = (findTheWinner(n - 1, k) + k) % n;
4-
return res ? res : n;
5-
}
1+
/**
2+
* @param {number} n
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
var findTheWinner = function (n, k) {
7+
if (n === 1) {
8+
return 1;
9+
}
10+
const ans = (k + findTheWinner(n - 1, k)) % n;
11+
return ans ? ans : n;
12+
};

0 commit comments

Comments
 (0)