题目链接:链表中环的入口结点
import java.util.*;
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode EntryNodeOfLoop(ListNode head) {
if(head == null || head.next == null || head.next.next == null) return null;
// 定义快慢指针 i j
ListNode i = head, j = head;
while(i != null && j != null)
{
i = i.next;
j = j.next;
if(j != null) j = j.next;
if(i == j)
{
i = head;
while(i != j)
{
i = i.next;
j = j.next;
}
return i;
}
}
return null;
}
}