首页
技术
登录
6mi
u
盘
搜
搜 索
技术
LeetCode:142. 环形链表 II
LeetCode:142. 环形链表 II
技术
2022-08-10
95
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
class
Solution
{
public
:
ListNode
*
detectCycle
(
ListNode
*
head
)
{
set
<
ListNode
*
>
obj
;
///为了防止元素内容相同,这里选择存储整个链表的节点
while
(
head
)
{
if
(
obj
.
count
(
head
)
==
1
)
{
return
head
;
}
obj
.
insert
(
head
)
;
head
=
head
-
>
next
;
}
return
NULL
;
}
}
;
转载请注明原文地址:https://ipadbbs.8miu.com/read-32770.html
最新回复
(
0
)