首页 > 其他 > 详细

Linked List Cycle II

时间:2014-03-19 03:25:09      阅读:368      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

 

bubuko.com,布布扣
 1     ListNode *detectCycle(ListNode *head) {
 2         if(!head||!head->next)
 3             return NULL;
 4         ListNode *fast,*slow;
 5         fast=head;
 6         slow=head;
 7         while(fast&&fast->next)
 8         {
 9             slow=slow->next;
10             fast=fast->next->next;
11             if(fast==slow)
12             {
13                 fast=head;
14                 while(fast!=slow)
15                 {
16                     fast=fast->next;
17                     slow=slow->next;
18                 }
19                 return fast;
20             }
21         }
22         return NULL;
23     }
bubuko.com,布布扣

AC

Linked List Cycle II,布布扣,bubuko.com

Linked List Cycle II

原文:http://www.cnblogs.com/crane-practice/p/3608742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!