Update 62. 圆圈中最后剩下的数.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:07 +08:00
parent 23d21cdfd4
commit 65558246db
+7 -5
View File
@@ -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;
}
```