当前位置:网站首页>The brave rice rice, does not fear the brush list of 】 list has a ring
The brave rice rice, does not fear the brush list of 】 list has a ring
2022-08-10 11:09:00 【rice, rice】
Foreword
This series mainly organizes the hand-tear code questions that need to be mastered in the interview.This section describes the problem of having cycles in linked lists.
Article table of contents
First, BM6 determines whether there is a cycle in the linked list

(1) Set the fast and slow pointer, and the fast pointer moves at a timeTwo spaces, the slow pointer moves one space at a time;
(2) If the fast pointer is not empty, then it will keep looping;
(3) If the fast pointer is equal to the slow pointer, it proves that there is a cycle in the linked list, if the fast pointer is equal to the slow pointerIf the pointer is empty, it proves that there is no cycle in the linked list.

function hasCycle( head ) {// write code herevar slow = head;var fast = head;while(fast && fast.next){slow = slow.next;fast = fast.next.next;if(slow == fast) return true}return false}Second, the entry node of the ring in the BM7 linked list


(1) Set the fast and slow pointer, the fast pointer moves two spaces at a time, and the slow pointer moves one space at a time;
(2) Same as the previous question, if the fast pointer == the slow pointer, it proves that there is a loop, and if the fast pointer is empty, there is no loop;
(3) If the fast pointer is equal to the slow pointer, let the slow pointer start from the beginning,Both hands move forward one frame at a time, and when the fast hand equals the slow hand, that position is the beginning of the ring.
边栏推荐
- STM32 encapsulation ESP8266 a key configuration function: implementations of AP mode and the STA mode switch, server and the client to create
- 这些年我开源的几个小项目
- In August the DB list latest scores - database Engines
- Text selection rounded style border-radius
- 越折腾越好用的 3 款开源 APP
- 短视频软件开发——平台同质化如何破局
- Techches Transformer the join wisdom source the author cao, visual basic model study
- 从脚本到剪辑,影像大师亲授的后期制作秘籍
- 【勇敢饭饭,不怕刷题之链表】链表倒数节点问题
- Get started quickly and conquer three different distributed architecture calling schemes
猜你喜欢

What is an abstract class

Situation丨The intrusion of hackers intensifies, and the shooting range sets up a "defense shield" for network security

js guessing game source code

【Azure云】服务端点和私有链接有什么区别?观点(1)

"MySQL Advanced Chapter" 6. Principles of index creation and design

「时序数据库」使用cassandra进行时间序列数据扫描
![[C language] Floating point number rounding](/img/ff/3f256deaa5ec82d692828c67cfb0fa.png)
[C language] Floating point number rounding

Open Office XML 格式里如何描述多段具有不同字体设置的段落

Dialogue with Chen Ciliang: Nezha wants to popularize high-end products

Memory problems difficult to locate, it is because you do not use ASAN
随机推荐
POJ 1026 Cipher (置换群)
3D rotating text animation js special effects
Store limited time seckill function system
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
2022.8.9-----leetcode.1413
企业如何判断数据治理是否成功?
Text selection rounded style border-radius
blocking non-blocking poll mechanism asynchronous
从产品维度来看 我们为什么不能完全信任Layer2?
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
what is rtems
金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
mysql5.7安装部署-yum安装
Interviewer: Dao, in Service, the Controller, Util, divided into the Model?
Codeforces 814 C. An impassioned circulation of affection (dp)
第2章-矩阵及其运算-矩阵运算(2)
网络安全笔记6——数字证书与公钥基础设施
【电商运营】你真的了解社交媒体营销(SMM)吗?
从脚本到剪辑,影像大师亲授的后期制作秘籍
Short video software development - how to break the platform homogenization