力扣第876题 链表的中间结点

力扣第876题 链表的中间结点

 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;
}
原文地址:https://www.cnblogs.com/woodjay/p/12555840.html