public class Solution {
public ListNode EntryNodeOfLoop(ListNode pHead) {
if (pHead == null) return null;
Set<ListNode> set = new HashSet<>();
ListNode tmp = pHead;
while (tmp != null) {
if (set.contains(tmp)) return tmp;
set.add(tmp);
tmp = tmp.next;
}
return null;
}
}
网友评论