/**
* 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*> A;
while(head){
if(!A.count(head)) A.insert(head);
else return head;
head=head->next;
}
return NULL;
}
};
Leecode 142. 环形链表 II
最新推荐文章于 2024-10-19 14:14:43 发布