1* Definition for singly-linked list.2* struct ListNode {3*int val;4*ListNode *next;5*ListNode()6: val(0),7next(nullptr){} * ListNode(int x)8: val(x),9next(nullptr){} * ListNode(int x, ListNode *next) : val(x), next(next){} *10};11*/ class Solution {12public:13ListNode *removeNthFromEnd(ListNode *head, int n) {14ListNode *n1 = new ListNode();15ListNode *temp = head;16ListNode *p = head;17ListNode *q = n1;18n1->next = head;19int count;20while (temp) {21if (n > 0) {22n--;23} else if (n == 0) {24cout < val;25p = p->next;26q = q->next;27}28temp = temp->next;29}30q->next = p->next;31delete p;32return n1->next;33}34};