Title list button 876 forces the intermediate node

Title list button 876 forces the intermediate node

 struct ListNode 
 {
     int val;
     ListNode *next;
     ListNode(int x) : val(x), next(NULL) {}
};

ListNode* middleNode(ListNode* head)
{
	ListNode *stepOne = head;
	ListNode *stepTwo = head;
	while (stepTwo != NULL && stepTwo->next != NULL)
	{
		stepOne = stepOne->next;
		stepTwo = stepTwo->next->next;
	}
	return stepOne;
}

Guess you like

Origin www.cnblogs.com/woodjay/p/12555840.html