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

 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;

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