1、双指针做法
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int kthToLast(ListNode* head, int k) {
ListNode* cru=head;
for(int i=0;i<k;++i) cru=cru->next;
while(cru!=NULL)
{
cru=cru->next;
head=head->next;
}
return head->val;
}
};