题目简介

LeetCode
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
typedef struct ListNode Node;
Node *Cycle(struct ListNode *head) {
Node* slow = head;
Node* fast = head;
while(fast && fast->next)
{
slow = slow->next;
fast = fast->next->next;
if(slow == fast)
return slow;
}
return NULL;
}
struct ListNode *detectCycle(struct ListNode *head) {
Node* meet = Cycle(head);
if(meet == NULL)
{
return NULL;
}
while(meet != head)
{
meet = meet->next;
head = head->next;
}
return meet;
}
博客主要介绍了LeetCode相关题目。围绕LeetCode展开,虽内容简短,但聚焦于题目方面的介绍。
1万+

被折叠的 条评论
为什么被折叠?



