环形链表
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
for(struct ListNode *f=head,*s=head;f&&f->next;)
{s=s->next,f=f->next->next;
if(f==s)return true;
}return false;
}
运用两个指针,巧妙利用追击相遇问题解法解决问题。并且时间复杂度:O(n)。