File tree Expand file tree Collapse file tree 3 files changed +7
-4
lines changed
Expand file tree Collapse file tree 3 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ class Solution {
8686
8787这还是一道约瑟夫环经典题。
8888
89+ > 另外一道同款题在 [ 这里] ( https://mp.weixin.qq.com/s?__biz=MzU4NDE3MTEyMA==&mid=2247490948&idx=1&sn=a71c4ec3529277ad119702d7dacf510e&chksm=fd9cb69bcaeb3f8d5461518a15d969b45a13558a4c5810100f40200a12aac66f1876f2ef6de7&token=831443013&lang=zh_CN#rd ) 🎉🎉
90+
8991每次往同一方向,以固定步长 $k$ 进行消数。由于下一次操作的发起点为消除位置的下一个点(即前后两次操作发起点在原序列下标中相差 $k$),同时问题规模会从 $n$ 变为 $n - 1$,因此原问题答案等价于 ` findTheWinner(n - 1, k) + k ` 。
9092
9193一些细节,由于编号从 $1$ 开始,在返回答案时我们需要将结果为 $0$ 的值映射回编号 $n$。
Original file line number Diff line number Diff line change 22
33这是 LeetCode 上的 ** [ 2335. 装满杯子需要的最短总时长] ( ) ** ,难度为 ** 简单** 。
44
5- Tag : 「递归」、「贪心 」、「数学 」、「排序 」
5+ Tag : 「排序」、「 递归」、「模拟 」、「贪心 」、「数学 」
66
77
88
@@ -55,7 +55,7 @@ Tag : 「递归」、「贪心」、「数学」、「排序」
5555
5656---
5757
58- ### 递归
58+ ### 排序 + 递归
5959
6060水的种类固定为 ` 3 ` ,且每种水的数据范围只有 $100$,可直接使用递归进行求解。
6161
@@ -67,7 +67,7 @@ class Solution {
6767 public int fillCups (int [] amount ) {
6868 Arrays . sort(amount);
6969 if (amount[1 ] == 0 ) return amount[2 ];
70- amount[1 ] -= 1 ; amount[2 ] -= 1 ;
70+ amount[1 ]-- ; amount[2 ]-- ;
7171 return 1 + fillCups(amount);
7272 }
7373}
Original file line number Diff line number Diff line change 66
77有任何问题欢迎你给我提 issue(issues 页有 [ 惊喜] ( https://github.com/SharingSource/LogicStack-LeetCode/issues/5 ) ) 🤣
88
9- ![ 宫水三叶的刷题日记] ( https://oscimg.oschina.net/oscnet/up-19688dc1af05cf8bdea43b2a863038ab9e5.png )
9+ ![ 宫水三叶的刷题日记] ( https://s1.ax1x.com/2023/06/25/pCN6HOJ.png )
10+
You can’t perform that action at this time.
0 commit comments