剑指offer---链表中倒数第k个节点
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) { ListNode* p1 = pListHead; ListNode* p2 = pListHead; int temp = k; if(pListHead == NULL || k <= 0) { return NULL; } temp--; while(temp--) { /* 链表的长度小于k */ p2 = p2->next; if(p2 == NULL) { return NULL; } } while(p2->next != NULL) { p1 = p1->next; p2 = p2->next; } return p1; } };