当前位置:网站首页>leetcode剑指offer JZ23:链表中环的入口节点
leetcode剑指offer JZ23:链表中环的入口节点
2022-07-24 05:22:00 【喜乐自在】

可以考虑利用set容器存放链表中的节点,根据set的不可重复,利用count函数判断是否存放重复数据。
unordered set的无序列排列即可
#include<iostream>
using namespace std;
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
class Solution {
public:
ListNode* EntryNodeOfLoop(ListNode* pHead) {
if(!pHead)
return NULL;
unordered_set<ListNode*>s1; //创建无序的set容器
while(pHead){ //头节点不为空,往后遍历
if(s1.count(pHead)){
return pHead; //如果s1.count()返回1.即if成立,s1中存在过pHead节点
}
else
s1.insert(pHead); //否则将pHead插入到set中
pHead=pHead->next; //节点后移动,继续遍历
}
return NULL;
}
};边栏推荐
- 利用内网穿透,实现公网访问内网
- Dameng database_ LENGTH_ IN_ Influence of char and charset
- Hololens 2 Chinese development document MRTK V2
- IP笔记(7)
- First knowledge of graphics
- 10大漏洞评估和渗透测试工具
- Openpose2d transform 3D pose recognition
- Foundation of JUC concurrent programming (8) -- read write lock
- Foundation of JUC concurrent programming (6) -- lock lock
- Search of two-dimensional array of "sword finger offer" C language version
猜你喜欢

使用Keras和LSTM实现对于长期趋势记忆的时间序列预测-LSTNet

JDBC advanced -- learning from Shang Silicon Valley (DAO)

配置固定的远程桌面地址【内网穿透、无需公网IP】

UE4 random generation of items

leetcode 不用加减乘除算加法 || 二进制中1的个数

Solve modularnotfounderror: no module named "cv2.aruco“

Hit the wall record (continuously updated)
![[principles of database system] Chapter 5 algebra and logic query language: package, extension operator, relational logic, relational algebra and datalog](/img/6a/c30b139823208a2e021135a4bf8d58.png)
[principles of database system] Chapter 5 algebra and logic query language: package, extension operator, relational logic, relational algebra and datalog

IP课(OSPF)综合实验

Jupyter notebook select CONDA environment
随机推荐
IP课(OSPF)综合实验
什么是单调栈
IP笔记(11)
ue4 物品随机生成
Unity基础知识及一些基本API的使用
IP笔记(6)
配置固定的远程桌面地址【内网穿透、无需公网IP】
IP课笔记(4)
Unity2d game let characters move - Part 1
Understanding of Flink parallelism
Foundation of JUC concurrent programming (4) -- thread group and thread priority
Sort ArrayList < ArrayList < double> >
不租服务器,自建个人商业网站(3)
Lua Foundation
leetcode剑指offer jz5 替换空格字符串
Installation of tensorflow and pytorch frames and CUDA pit records
Lunix命令入门 - 用户及文件权限(chmod 详解)
Unity Shader从内置渲染管线迁移到URP
Foundation of JUC concurrent programming (1) -- related basic concepts
HoloLens 2 开发:开发环境部署