zoukankan      html  css  js  c++  java
  • 所谓找链表中点

    // at least two nodes
    if(!head || !head->next) return head;
    
    // find the middle node
    ListNode *slow = head;
    ListNode *fast = head;
    while(fast->next && fast->next->next) {
        slow = slow->next;
        fast = fast->next->next;
    }

    // at least two nodes
    if(!head || !head->next) return head;
    
    // find the middle node
    ListNode *slow = head;
    ListNode *fast = head->next->next;
    while(fast && fast->next) {
        slow = slow->next;
        fast = fast->next->next;
    }

     

  • 相关阅读:
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
  • 原文地址:https://www.cnblogs.com/daijkstra/p/4861507.html
Copyright © 2011-2022 走看看