mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 16:06:24 +00:00
Update 62. 圆圈中最后剩下的数.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -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;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user