From 65558246dbdc0afacbf779c4e3794003393375b5 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:07 +0800 Subject: [PATCH] =?UTF-8?q?Update=2062.=20=E5=9C=86=E5=9C=88=E4=B8=AD?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E5=89=A9=E4=B8=8B=E7=9A=84=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/62. 圆圈中最后剩下的数.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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; } ```