struct ListNode
{
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
ListNode *RemoveNthFromEnd(ListNode *head, int n)
{
ListNode * p = head;
while(n-- > 0 && p != NULL)
p=p->next;
ListNode ** remove = &head;
while(p != NULL)
{
p = p->next;
remove = &((*remove)->next);
}
*remove = (*remove)->next;
return head;
}