为什么判断环形列表出口的这段代码会出现错误?
```java
public ListNode detectCycle(ListNode head) {
ListNode fast = head;
ListNode slow = head;
if(head==null||head.next==null)
return null;
while (fast != null && fast.next != null && fast != slow) {
slow = slow.next;
fast = fast.next.next;
}
if (fast != slow)
return null;
while (head != fast) {
head = head.next;
fast = fast.next;
}
return fast;
}
```