LeetCode 链表中倒数第k个节点

ListNode* getKthFromEnd(ListNode* head, int k)
{
	ListNode* former = head;
	ListNode* latter = head;
	for (int i = 0; i < k; i++)
	{
		former = former->next;
	}
	while (former != NULL)
	{
		former = former->next;
		latter = latter->next;
	}
	//cout << latter->val << endl;
	return latter;
}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页