leetcode-剑指22-OK
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* getKthFromEnd(struct ListNode* head, int k){
int getlenth(struct ListNode* head){
int len = 0;
while(head!=NULL){
len++;
head = head->next;
}
return len;
}
k = getlenth(head)-k;
while(k>0){
k--;
head = head->next;
}
return head;
}