Classic application of two pointers: slow and fast.
Algorithm: when fast catches up with slow, there is cycle.
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
Soulution:
1 | class Solution(object): |