/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pListHead ListNode类
* @param k int整型
* @return ListNode类
*/
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {
// write code here
struct ListNode * cur = pListHead;
int n=0;
while(cur)
{
cur=cur->next;
++n;
}
if(k>n)
{
return NULL;
}
n=n-k;
cur=pListHead;
while(n)
{
cur=cur->next;
n--;
}
return cur;
}

京公网安备 11010502036488号