public boolean hasCycle(ListNode head)
{
if(head==null) return false;
ListNode fast = head;
ListNode slow = head;
while(1==1){
if(fast.next!=null&&fast.next.next!=null)
{
fast=fast.next.next;
slow=slow.next;
}
else {
return false;
}
if (slow==fast)
{
return true;
}
}
}
leetcode 141 Java 快慢指针

最新推荐文章于 2024-12-14 15:04:31 发布
