题解 | #链表中倒数第k个结点#
链表中倒数第k个结点
https://www.nowcoder.com/practice/529d3ae5a407492994ad2a246518148a
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pListHead ListNode类
* @param k int整型
* @return ListNode类
*/
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {
struct ListNode* slow = pListHead, *fast = pListHead;
int count = k;
while(count--)
{
if(fast ==NULL)
return NULL;
fast = fast->next;
}
while(fast)
{
fast = fast->next;
slow = slow->next;
}
return slow;
// write code here
}
查看22道真题和解析
阿里云工作强度 710人发布
