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; }