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

2.6---找有环链表的开头结点(CC150)

时间:2015-12-18 10:36:29      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

 public ListNode detectCycle(ListNode head) {
        
    ListNode fast = head;
    ListNode slow = head;
    int flag = 0;
    ListNode intersection = null;
    while(fast != null && fast.next != null){
        fast = fast.next.next;
        slow = slow.next;
        if(fast == slow){
            intersection = fast;
            flag = 1;
            break;
        }
    }
    if(flag == 0 ) return null;
    slow = head;
    while(slow != fast){
        slow = slow.next;
        fast = fast.next;
        
    }
    return fast;

    }

 

2.6---找有环链表的开头结点(CC150)

标签:

原文地址:http://www.cnblogs.com/yueyebigdata/p/5056067.html

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