算法(C++):
/**
* 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) {
ListNode* p = head;
int cnt = 0;
while(p != NULL){
cnt++;
p = p->next;
}
p = head;
for(int i = 0;i < cnt/2;++i){
p = p->next;
}
return p;
}
};