链表中环的入口结点 发表于 2018-10-03 | 分类于 数据结构与算法 , 题目汇总 题目描述一个链表中包含环,请找出该链表的环的入口结点。 1234567891011121314151617181920212223242526272829303132/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode EntryNodeOfLoop(ListNode pHead){ if(pHead == null || pHead.next == null){ return null; } ListNode node1 = pHead; ListNode node2 = pHead; while(node2 != null){ node1 = node1.next; node2 = node2.next.next; if(node1 == node2){ break; } } node1 = pHead; while(node1 != node2){ node1 = node1.next; node2 = node2.next; } return node1; }}