/** * 用hashMap保存下个节点的前驱节点,当key有多个前驱节点就是入口 * * @param pHead * @return */ public static ListNode EntryNodeOfLoop(ListNode pHead) { Map<ListNode, ListNode> map = new HashMap<>(); if (pHead == null || pHead.next == null) { return null; } ListNode next = pHead; while (next != null) { if (map.get(next.next) == null) { map.put(next.next, next); } else { if (next != pHead) { return next.next; } else { return next; } } next = next.next; } return null; }