当前位置:网站首页>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.
边栏推荐
- The usage and difference between getParameter() and getAttribute()
- HDU 1520 Anniversary party (树型dp)
- Pycharm终端出现PS问题、conda或activate不是内部命令问题..
- 技能大赛训练题:组策略一
- GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
- Dry goods!ASSANet: Making PointNet++ faster and stronger
- Summary of whitespace, space and escape characters in C language
- blocking non-blocking poll mechanism asynchronous
- Open Office XML 格式里如何描述多段具有不同字体设置的段落
- HDU 1520 Anniversary party (tree dp)
猜你喜欢

【勇敢饭饭,不怕刷题之链表】链表反转的几种情况

C#实战:基于ItextSharp技术标签生成小工具

owl.carousel海报卡片Slider轮播切换

chart.js水平柱状图插件

Redis (three) - detailed configuration file, publish and subscribe, new data types

兼容移动和PC的loading加载和toast消息插件

Network Security Note 6 - Digital Certificates and Public Key Infrastructure

STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建

Unsafe的一些使用技巧

ISO9001在讲什么?过程方法和风险思维
随机推荐
突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
Three-phase 380V rectified voltage
3 injured in 'electrical accident' at Google data center
Mount [shell][mount -o loop]
In August the DB list latest scores - database Engines
兼容移动和PC的loading加载和toast消息插件
1-IMU参数解析以及选择
开发模式对测试的影响
2022年裁员潮,失业程序员何去何从?
MongoDB database notes
2022.8.7-----leetcode.636
Network Security Note 6 - Digital Certificates and Public Key Infrastructure
杭电多校-Loop-(不确定性贪心+线段树)
OneFlow source code parsing: operator instructions executed in a virtual machine
关于json转换器缺失的问题,报错内容:No converter found for return value of type
Several small projects that I have open sourced over the years
"Data Strategy" Results-Driven Enterprise Data Strategy: Organization and Governance
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
Redis6(一)——NoSQL数据库简介与Redis的安装
TCP/IP笔记