当前位置:网站首页>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
边栏推荐
- 测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
- The Thread State,
- 基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】
- 罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
- MySQL高级指令
- LeetCode每日两题02:反转字符串中的单词 (均1200道)
- How to translate financial annual report, why choose a professional translation company?
- Intelligent scheme design - intelligent rope skipping scheme
- 高通平台开发系列讲解(应用篇)QCMAP应用框架介绍
- STL-deque
猜你喜欢
电力系统潮流计算(牛顿-拉夫逊法、高斯-赛德尔法、快速解耦法)(Matlab代码实现)
边缘与云计算:哪种解决方案更适合您的连接设备?
这些不可不知的JVM知识,我都用思维导图整理好了
服务——DNS正向反向域名解析服务
C # Hex file transfer skills necessary article 】 【 bin file code implementation
Live Classroom System 09--Tencent Cloud VOD Management Module (1)
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
shell脚本
黑猫带你学Makefile第13篇:Makefile编译问题合集
An article to teach you a quick start and basic explanation of Pytest, be sure to read
随机推荐
win系统下pytorch深度学习环境安装
ASCII、Unicode和UTF-8
camera preview process --- from HAL to OEM
[SQL brush questions] Day3----Special exercises for common functions that SQL must know
特别的三杯鸡
Black cat takes you to learn Makefile Part 11: When the header file a.h changes, how to recompile all the .c files that depend on the header file a.h
LeetCode每日两题02:反转字符串中的单词 (均1200道)
自组织是管理者和成员的双向奔赴
Conditional Statements of Shell Programming (2)
LeetCode Daily Question (1573. Number of Ways to Split a String)
xshell (sed command)
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
HighTec快捷键(Keys)设置位置
TCP连接过程中如果拔掉网线会发生什么?
How to translate financial annual report, why choose a professional translation company?
Application of Spatial 3D Model Reconstruction Based on Pix4Dmapper - Spatial Analysis and Site Selection
【PCBA solution】Electronic grip strength tester solution she'ji
These must-know JVM knowledge, I have sorted it out with a mind map
APP UI自动化测试常见面试题,或许有用呢~
阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会