# 1. 题目描述
给定一个有环链表,返回第一个入环节点。
# 2. 题解
快慢指针
~~~
/**
* 快慢指针
* @param list 待判断有环链表
* @return 环入口或者null
*/
public Node findStartNode(Node list){
if(list == null) return null;
Node fast = list, slow = list;
boolean flag = false;
while(fast != null && fast.next != null){
slow = slow.next;
fast = fast.next.next;
if(slow == fast) {
flag = true;
break;
}
}
if(!flag) return null;
fast = list;
while(fast != slow){
fast = fast.next;
slow = slow.next;
}
return fast;
}
~~~