public class Node{public int val;public Node next;}public boolean isHasLoop(Node head){if(head == null) return false;Node slow = head.next;if(slow == null) return false;Node fast = slow.next;while(fast != null && slow != null){if(fast == slow) return true;slow = slow.next;fast = fast.next;//快指针走两步时,要注意避免空指针异常if(fast != null) fast = fast.next;}return false;}
