码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode--010 Linked List Cycle II

时间:2014-07-31 16:01:36      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   art   ar   div   amp   

bubuko.com,布布扣

 

 

 1 public ListNode detectCycle(ListNode head) {
 2         ListNode s=head;
 3         ListNode f=head;
 4         while(f!=null&&f.next!=null){
 5             s=s.next;
 6             f=f.next.next;
 7             if(s==f){
 8                 break;
 9             }
10         }
11         if(f==null||f.next==null)
12             return null;
13         s=head;
14         while(s!=f){
15             s=s.next;
16             f=f.next;
17         }
18         return s;
19     }

 

leetcode--010 Linked List Cycle II,布布扣,bubuko.com

leetcode--010 Linked List Cycle II

标签:style   blog   color   os   art   ar   div   amp   

原文地址:http://www.cnblogs.com/thehappyyouth/p/3880643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!