Sunday, September 14, 2014

Linked List Cycle

Problem

Given a linked list, determine if it has a cycle in it.

Follow up:
Can you solve it without using extra space?

Idea

设置两个指针,一个每次移动2步,一个每次移动1步。 若最终相遇则有环,若一个指针走到了NULL,则没环

Solution


No comments:

Post a Comment