当前位置:网站首页>BM7 list entry in central
BM7 list entry in central
2022-08-10 22:31:00 【Rice white】


Review questions:
If the second linked list given is not empty, there must be a cycle.
Let's fix two special cases first:
{1}, {} // no loop, return null directly
{}, {2} //There is a loop, return any node of the second linked list

ok...okay
We look at the function input given by the title, there is only one parameter, then pHead has linked the two linked lists.
Well, I'm overthinking it, it seems it's a simple matter of finding the point of entry....
Hee hee, sorry, sorry....
As for Mao, I will explain it in such simple words, not because the algorithm is inherently abstract and difficult to understand, it will be easier to understand and empathize with this expression...Woohoo, it's really hard work, it's not easy to create, please pay attention,,, hee hee
How to judge whether there is a ring:
It is ok through the speed pointer
Fast pointer, take two steps at a time, slow pointer one step at a time (in fact, I feel that the fast pointer is ok as long as it is faster than the slow pointer)
1. Assuming there is no ring, can it be understood that the two pointers start from the same starting point and march along an endless road
2. Assuming there is a ring, how to understand it?
Suppose that one day you secretly go out to surf the Internet, your father finds out, and goes to the Internet cafe to catch you.Then you run to the school playground, stop, and you say to your dad, "Stupid old man, you can't catch me"....
You and your dad start at the same starting point at the same time (both from your internet cafe seat), your dad is twice as fast as you, and then when you run to the playground, you run along the playground.Your dad is chasing you.As long as your dad is faster than you, he will definitely be able to catch you.How to say, I don't know how to understand Bo (if you have any questions, you can send a private message)
How to find the entry node:
According to XXX mathematicians, Forgive my ignorance, I just know the theory....
The distance from the point to the entry point where fast and last meet is the same as the distance from the starting point to the entry point

The idea is analyzed, and the code is uploaded
Don't tell me you can't write code, just adjust slowly....You can learn from it, but not copy it

/*struct ListNode {int val;struct ListNode *next;ListNode(int x) :val(x), next(NULL) {}};*/class Solution {public:ListNode* EntryNodeOfLoop(ListNode* pHead) {ListNode *fast = nullptr;ListNode *last = nullptr;ListNode *p = nullptr;if(pHead->next == nullptr || pHead->next->next == nullptr){return p;}fast = pHead->next->next;last = pHead->next;while(1){if(fast == nullptr || fast == last){break;}if(fast->next != nullptr){fast = fast->next->next;}else{fast = nullptr;}last = last->next;}if(fast == last){p = pHead;while(1){if(p == last){break;}p = p->next;last = last->next;}}return p;}};Daily complaints:
Write a question for three minutes, and write a blog question and solve it for ten years
边栏推荐
猜你喜欢

camera预览流程 --- 从HAL到OEM

黑猫带你学Makefile第13篇:Makefile编译问题合集

Redis Performance Impact - Asynchronous Mechanisms and Response Latency

RADIUS Authentication Server Deployment Costs That Administrators Must Know

C#【必备技能篇】Hex文件转bin文件的代码实现

阿里云架构师金云龙:基于云XR平台的视觉计算应用部署

接口测试的概念、目的、流程、测试方法有哪些?

unusual understanding

c语言之 练习题1 大贤者福尔:魔法数,神奇的等式

LeetCode每日两题02:反转字符串中的单词 (均1200道)
随机推荐
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
QT笔记——用VS + qt 生成dll 和 调用生成的dll
MySQL Advanced Commands
Service - DHCP principle and configuration
What is Jmeter? What are the principle steps used by Jmeter?
阿里巴巴、蚂蚁集团推出分布式数据库 OceanBase 4.0,单机部署性能超 MySQL
RTL8721DM 双频WIFI + 蓝牙5.0 物联网(IoT)应用
美味石井饭菜
LeetCode每日两题02:反转字符串中的单词 (均1200道)
BM7 链表中环的入口结点
什么是Jmeter?Jmeter使用的原理步骤是什么?
管理员必须知道的RADIUS认证服务器的部署成本
shell编程之正则表达式与文本处理器
H3C S5130 IRF做堆叠
如何成为一名正义黑客?你应该学习什么?
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
Likou 215 questions, the Kth largest element in an array
QT笔记——vs + qt 创建一个带界面的 dll 和 调用带界面的dll

