当前位置:网站首页>Why use the fast and slow pointer to find the link of the linked list, and the fast pointer and the slow pointer must meet?
Why use the fast and slow pointer to find the link of the linked list, and the fast pointer and the slow pointer must meet?
2022-07-21 20:37:00 【Lotus awn】
You can think about this problem by mathematical induction . First , Because the linked list is a ring , So the process of meeting can be seen as the process of the fast pointer catching up with the slow pointer from behind . Then do the following thinking :
- The difference between the fast pointer and the slow pointer is one step . Now continue to walk back , Slow pointer forward one step , Move the pointer forward two steps , The two meet .
- There is a difference of two steps between the fast pointer and the slow pointer . Now sigh and walk back , Slow pointer forward one step , Move the pointer forward two steps , The difference between the two is one step , Into the first case .
- Difference between fast pointer and slow pointer N Step . Now continue to walk back , Slow pointer forward one step , Move the pointer forward two steps , The difference between the two is (N+1-2)-> N-1 Step .
therefore , This question is proved . So the fast pointer must meet the slow pointer . And because the speed of the fast pointer is twice that of the slow pointer , So when we meet, we must only make a circle .
边栏推荐
- Available parameters are [list] error in batch upload
- Object.prototype.toString.call()的原理
- Namespace namespace
- Click the back button to return to the previous page
- Data analysis on the fourth match
- 20.【char*与string相等不相等】
- Understand the three mountains of JS
- My first blog
- Fifth Bureau akali teaching Bureau
- js动态实现倒计时功能
猜你喜欢
1027 print hourglass
Let the code solve the series of "linear algebra" - find the greatest common factor of polynomials
visual studio第三方库添加——Eigen
Record some little cheese about writing the program ~ [continue to be more ~]
Object.prototype.toString.call()的原理
Custom MVC principle
MySQL导入导出&视图&索引&执行计划
C语言实现三子棋小游戏---格局打开版(
2020常州市程序设计小能手真题及题解
Namespace namespace
随机推荐
Dynamically listen for the height of DOM elements
useMemo和useCallback的区别以及使用场景
[C language] choose and cycle to interpret romantic source code
Record some little cheese about writing the program ~ [continue to be more ~]
1027 print hourglass
Crud of MySQL
受控组件和非受控组件的区别
使用tailwind在谷歌浏览器上,button会出现蓝色背景的问题
Acwing 175 circuit maintenance
Deep analysis of string -- strchr & strstr
How to get the second child element under the first child element
格式化时间
VS,MATLAB,leetcode注释快捷键
xml建模
如何免费在本地播放flv格式的视频
重置表单
Data analysis of akali teaching Bureau in the first half of the fifth set
移动端 pc端 小程序 UI框架选择
开发模式下热更新 加快开发环境代码更新
Custom MVC framework implementation