Your question is Cycle Detection in Linked Lists. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given the head of a singly linked list, determine whether the list contains a cycle. A cycle exists if a node can be reached again by continuously following next pointers.
Return True if the linked list has a cycle, otherwise return False.
head, the head node of a singly linked list. Each node has fields val and next.You must solve the problem without modifying the linked list structure.
def has_cycle(head):