Three cases:
- Acyclic list
- Completely cyclic list (all nodes are in the cycle/loop)
- Partially cyclic list (at least one node not in the cycle/loop)
Requirement: O(n) in time and O(1) in space.
Case 2 is similar to Case 1, except for the test condition of list tail and the corresponding update to original head.
Here is the code for this case.
Related Posts:
Discussion about Case 1
Discussion about Case 3
No comments:
Post a Comment