public boolean hasCycle(ListNode head) {
ListNode slow, fast;
slow = fast = head;
while(slow != null && fast != null && fast.next != null)
{
slow = slow.next;
fast = fast.next.next;
if(slow == fast)
{
return true;
}
}
return false;
}
[leetcode] Linked List Cycle
最新推荐文章于 2024-06-07 08:25:31 发布