走两次
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* middleNode(ListNode* head) {
// gain list size
int len = 0;
ListNode * start = head;
while(start!=NULL){
len ++;
start = start->next;
}
// 5
cout<<len<<endl;
int mid = ceil((len+1)/2.0);
while(mid>1){
mid --;
head = head->next;
}
return head;
}
};