替我找错误
链表中环的入口结点
http://www.nowcoder.com/questionTerminal/253d2c59ec3e4bc68da16833f79a38e4
正确的我就不说了。
为啥下面的解法不对?
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } */ import java.util.*; public class Solution { //方案2:双指针 public ListNode EntryNodeOfLoop(ListNode pHead) { if(pHead==null||pHead.next==null||pHead.next.next==null) return null; ListNode fast = pHead.next.next; ListNode slow = pHead; while(true){ if(fast==slow){ fast = pHead; break; } if(fast.next==null||fast.next.next==null){ return null; } fast = fast.next.next; slow = slow.next; } while(fast!=slow){ fast = fast.next; slow = slow.next; } return fast; } }