对null的情况要进行说明 不然会报错
为啥会报错呢
搞不懂
import java.util.*;
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode Circle(ListNode head){
if(head==null){
return null;
}
ListNode fast=head;
ListNode slow=head;
while(fast!=null&&fast.next!=null){
fast=fast.next.next;
slow=slow.next;
if(fast==slow){return slow;}
}
return null;
}
public ListNode EntryNodeOfLoop(ListNode pHead) {
ListNode slow=Circle(pHead);
if(slow==null){return null;}
ListNode fast=pHead;
while(fast!=slow){
fast=fast.next;
slow=slow.next;
}
return slow;
}
}