标签:offer color log public find int ret span 倒数第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; } };
标签:offer color log public find int ret span 倒数第k个节点
原文地址:http://www.cnblogs.com/159269lzm/p/7295272.html