思路:采用快慢指针,若有环 快慢指针一定会在某处相等
public boolean checkCycle(ListNode head){ if(head==null) return fasle; ListNode slow = head; ListNode fast = head; while(fast!=null&&fast.next!=null){ slow = slow.next; fast = fast.next.next; if(slow==fast) return true; } return false; }