Linked List Cycle

Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
A straightforward way is to use hashset.
A trick one is to use slow/fast runner. Slow runner moves forward one step where fast runner moves forward two steps. If there is a cycle they will eventually meet.

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs