用一个集合存储地址,重复了代表链表成环了。

/*
 public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
*/
import java.util.*;
public class Solution {

    public ListNode EntryNodeOfLoop(ListNode pHead) {
        Set<ListNode> we = new HashSet<>();
        for(;pHead != null;){
            if(!we.add(pHead)){
                return pHead;
            }
            pHead = pHead.next;
        }
        return null;
    }
}