Cycle DetectionMedium
A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine if it contains a cycle. If it does, return \(1\). Otherwise, return \(0\).
Example
\(head\) refers to the list of nodes \(1 \to 2 \to 3 \to NULL\)
The numbers shown are the node numbers, not their data values. There is no cycle in this list so return \(0\).
\(head\) refers to the list of nodes \(1 \to 2 \to 3 \to 1 \to NULL\)
There is a cycle where node 3 points back to node 1, so return \(1\).