Happiness is more than pleasure without pain

你只有非常努力,才能看起来毫不费力

导航

Linked List Cycle

//快慢指针

public class Solution {
public boolean hasCycle(ListNode head) {
if(head==null)return false;
ListNode slow=head;
ListNode fast=head;
do{
if(fast==null||fast.next==null)return false;
fast=fast.next.next;
slow=slow.next;
} while(fast!=slow);
return true;
}
}

posted on 2015-03-26 22:34  believer  阅读(96)  评论(0编辑  收藏  举报