// 题目描述
// 一个链表中包含环,请找出该链表的环的入口结点。
public class ListNode {
int val;
ListNode next =
null;
ListNode(int val) {
this.val =
val;
}
}
public ListNode EntryNodeOfLoop(ListNode pHead) {
ArrayList<ListNode> arrayList =
new ArrayList<ListNode>
();
ListNode listNode =
null;
while (pHead!=
null){
if (arrayList.contains(pHead)){
listNode =
pHead;
break;
}
arrayList.add(pHead);
pHead =
pHead.next;
}
return listNode;
}
转载于:https://www.cnblogs.com/kaibing/p/9103459.html
转载请注明原文地址: https://win8.8miu.com/read-2893.html