/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param pListHead ListNode类 * @param k int整型 * @return ListNode类 */ struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) { //思路一,要找倒数第k个,那就是找正数第n-k+1个,先求出链表长度,减去k再加一 int n = 0; int m = 0; if (pListHead == NULL) return NULL; struct ListNode* cur = pListHead; while (cur) { n++; cur = cur->next; } m = n - k + 1; cur = NULL; if (m > 0) { cur = pListHead; while (--m) { cur = cur->next; } } return cur; }