classSolution { public: ListNode*removeNthFromEnd(ListNode*head, intn) { ListNode*dummy=newListNode(0, head); ListNode*first=head; ListNode*second=dummy; for (inti=0; i<n; ++i) { first=first->next; } while (first) { first=first->next; second=second->next; } second->next=second->next->next; ListNode*ans=dummy->next; deletedummy; returnans; } };