题解 | #删除链表的倒数第n个节点#
删除链表的倒数第n个节点
https://www.nowcoder.com/practice/f95dcdafbde44b22a6d741baf71653f6
struct ListNode* removeNthFromEnd(struct ListNode* head, int n ) { struct ListNode* h = (struct ListNode*)malloc(sizeof(struct ListNode)); h->next = head; head = h; struct ListNode* fast = head; struct ListNode* slow = head; while(n--) { if(fast == NULL) return NULL; fast = fast->next; } while(fast->next) { fast = fast->next; slow = slow->next; } slow->next = slow->next->next; struct ListNode* ret = h->next; free(h); return ret; }