public static bool HasCircle(LeetCode141Node head) { if (head == null) { return(false); } var slow = head; var fast = head; while (fast != null && fast.next != null) { // fast go two steps each time fast = fast.next.next; // slow go one step each time slow = slow.next; if (fast == slow) { return(true); } } return(false); }
public LeetCode141Node(int x) { val = x; next = null; }