/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
int kthToLast(struct ListNode* head, int k){
struct ListNode*fast=head;
struct ListNode*slow=head;
int i=0;
for(i=0;i<k;i++)
{
fast =fast ->next;
}
while(fast!=NULL)
{
fast=fast->next;
slow=slow->next;
}
return slow->val;
}
力扣oj :返回倒数第k个节点
最新推荐文章于 2024-08-21 11:17:39 发布