Detect a cycleMedium
Let's say you're given a singly linked list.
Write a function that determines if it has a cycle.
A cycle implies that the list has a loop, where a node points to a previous node in the list.
Here's an example of a singly linked list without a cycle, where Node 5 has no
And here's a linked list with a cycle:
Note how Node 5 points back to Node 3.