This commit is contained in:
fanxb 2021-04-20 14:16:39 +08:00
parent ef7d8b9709
commit 2529cfc7b1
2 changed files with 3 additions and 1 deletions

View File

@ -18,7 +18,7 @@ categories:
1. 定义两个指针slow(慢指针每次走1个)fast(快指针,每次走两个),都从head出发。
2. 每进行一次移动fast和slow间隔的节点就会+1,由此可以推断当slow进入环后一定会和fast相遇
<!-- readmore -->
<!-- more -->
3. 假设链表非环的长度为a,环的长度为b,fast走过的距离为f,slow走过的距离为s,当fast在环中循环n次后fast,slow首次相遇可得到如下表达式
f=2s(f的速度是s的两倍)

View File

@ -22,6 +22,8 @@ categories:
3. 如数字和>=k说明能否满足i=i+1,s=s+1,重复第一步
4. 直到所有的数字都填入
<!-- more -->
java代码见[点击这里](https://github.com/FleyX/demo-project/blob/master/5.leetcode/src/com/fanxb/interview/Q1663.java),translateNum1方法
进一步思考会发现上面的解法存在存在很多的循环,效率不高,能否优化?