判断链表中是否有环
快慢指针即可。
public boolean hasCycle(ListNode head) {
if (head==null) return false;
ListNode fast=head;
ListNode slow=head;
do {
if(fast==null||fast.next==null) return false;
fast=fast.next.next;
slow=slow.next;
}while (fast!=slow);
return true;
}