LeetCode141.环形链表
题目
代码
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next; * };
*/
bool hasCycle(struct ListNode *head)
{
struct ListNode* fast = head;
struct ListNode* slow = head;
while (fast != 0 && fast->next != 0)
{
fast = fast->next->next;
slow = slow->next;
if (fast == slow)
return true;
}
return false;
}