所谓找链表中点

// 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;
}

 

posted @ 2015-10-08 16:53  daijkstra  阅读(332)  评论(0编辑  收藏  举报