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; }
上一篇:ORACLE 如何查看索引重建进度情况


下一篇:The first day!!!