Does the list loop?
A linked list may have a cycle: some node's next points back to an earlier node, so
walking it never ends. Write has_cycle(head) that returns whether it does, without
using extra memory proportional to the length.
has_cycle(1 -> 2 -> 3 -> back to 2) -> True
has_cycle(1 -> 2 -> 3) -> False
The point is to practise fast and slow pointers: in a cycle, the fast one laps the slow one.
def has_cycle(head):
...