力扣第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;
}
标签:力扣,head,ListNode,876,next,链表,stepTwo,stepOne,NULL 来源: https://www.cnblogs.com/woodjay/p/12555840.html