package suanfa.list;
import java.util.HashSet;
import java.util.Set;
/**
链表中环的入口结点
/
public class EntryNodeOfLoop {public ListNode EntryNodeOfLoop(ListNode pHead) {
Set<ListNode> set = new HashSet<>(); while (pHead != null) { if (set.contains(pHead)) { return pHead; } else { set.add(pHead); } pHead = pHead.next; } return null;
}
static class ListNode {
int val; ListNode next;
}
}