/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pHead ListNode类
* @param k int整型
* @return ListNode类
*/
struct ListNode* FindKthToTail(struct ListNode* pHead, int k ) {
// write code here
if(!pHead)return NULL;
if(k==0)return NULL;
struct ListNode* L1,*L2;
L1=L2=pHead;
for(int i=1;i<k;i++){
if(!L1->next)return NULL;
else{
L1=L1->next;
}
}
while(L1->next){
L1=L1->next;
L2=L2->next;
}
return L2;
}



京公网安备 11010502036488号