Problem
Given a linked list, determine if it has a cycle in it.
Solution
Method: Two Pointer
Time Complexity: O(n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |
or
1 | # Definition for singly-linked list. |
Pitfalls
- the input linked list has no cycle => return false
- the input linked list has cycle => return true