141. Linked List Cycle
Looping criterion is only related to the fast pointer, since it always meets the end before slow.
There are three conditions to consider:
There is only one node in linked list
There are more than one node and the fast node reaches the final loop:
fast jumps two steps each time, it could be the tail node
Or it could be the tail.next (None)
Note: When using linked list, always checking whether each next is valid or not.
Last updated