Given the head of a linked list, determine if the list has a cycle. A cycle exists if some node's next pointer points back to a previous node, creating a loop.
If you traverse naively, you'll loop forever. Example: (4 points back to 2) has a cycle. The naive approach uses a hash set to track visited nodes.
space. Can you detect cycles in space? Constraints: up to nodes.