leetcode-006 detect cycle

 package leetcode;

 public class DetectCycle {
public ListNode detectCycle(ListNode head) {
ListNode s=head;
ListNode f=head;
while(f!=null&&f.next!=null){
s=s.next;
f=f.next.next;
if(s==f){
break;
}
}
if(f==null||f.next==null)
return null;
s=head;
while(s!=f){
s=s.next;
f=f.next;
}
return s;
}
}
上一篇:采集爬虫中,解决网站限制IP的问题? - wendi_0506的专栏 - 博客频道 - CSDN.NET


下一篇:UVA 10131 Is Bigger Smarter?(DP最长上升子序列)