环形链表
代码目的:
给定一个链表,判断这个链表中是否有环。
class Solution {
public:
bool hasCycle(ListNode *head) {
ListNode*f=head;
ListNode*s=head;
if(f==NULL)
{return false;}
while(f!=NULL&&f->next!=NULL)
{
f=f->next->next;
s=s->next;
if(f==s)
{return true;}
}
return false;
}
};
代码的输出达到预期结果。

