cpp
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
int length=0;
ListNode* result=new ListNode();
ListNode* cur =head;
result=cur;
while(cur!=NULL)
{
length++;
cur=cur->next;
}
cur=head;
if((length-n)==0) return cur->next;
for(int i=0;i<length-n-1;i++)
{
cur=cur->next;
}
cur->next=cur->next->next;
return result;
}
};