/**
* 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) {
if(head == NULL || head->next == NULL)
return head;
ListNode *fast,*slow;
fast=head->next;slow=head;
while(fast != NULL)
{
slow=slow->next;
if(fast->next != NULL)
fast=fast->next->next;
else
break;
}
return slow;
}
};