/**
* 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* n;
n = head;
int count = 0;
while(n!=NULL)
{
count ++;
n = n->next;
}
n = head;
for(int i=0;i<count/2;i++)
{
n = n->next;
}
return n;
}
};
先遍历一般确定链表的大小,再从头遍历