Cycle Detection: Hare 🐇 and Tortoise 🐢
Example 1: head = [3, 2, 0,
-4], pos = 1
ListNode slow = head, fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast) {
return true;
}
}
return false;
Step: 0 / 0