标签:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ListNode * getmid(ListNode *head) { if(!head||!head->next || !head->next->next) return head ;// 空节点,一个节点或者两个节点 ListNode *mid = head ; ListNode * fast = head ; while(NULL!= fast->next && NULL!=fast->next->next) { mid = mid->next; fast = fast->next->next; } return mid; } input:1 2 3 4 5 6 7 8 9 output:5 6 7 8 9
标签:
原文地址:http://www.cnblogs.com/deanlan/p/4718541.html