diff --git a/notes/62. 圆圈中最后剩下的数.md b/notes/62. 圆圈中最后剩下的数.md index 47929d9c..3418466b 100644 --- a/notes/62. 圆圈中最后剩下的数.md +++ b/notes/62. 圆圈中最后剩下的数.md @@ -2,7 +2,7 @@ ## 题目链接 -[NowCoder](https://www.nowcoder.com/practice/f78a359491e64a50bce2d89cff857eb6?tpId=13&tqId=11199&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) ## 题目描述 @@ -13,11 +13,13 @@ 约瑟夫环,圆圈长度为 n 的解可以看成长度为 n-1 的解再加上报数的长度 m。因为是圆圈,所以最后需要对 n 取余。 ```java -public int LastRemaining_Solution(int n, int m) { - if (n == 0) /* 特殊输入的处理 */ +public int iceBreakingGame(int num, int target) { + if (num <= 0) { return -1; - if (n == 1) /* 递归返回条件 */ + } + if (num == 1) { return 0; - return (LastRemaining_Solution(n - 1, m) + m) % n; + } + return (iceBreakingGame(num - 1, target) + target) % num; } ```