class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
if( n <= 0)
return NULL;
ListNode *First = head, *Second = head;
int i = 0;
for( ; i < n; i ++)
{
if(First->next)
First = First->next;
else
break;
}
if( i == n - 1)
{
ListNode *tmp = head->next;
delete head;
return tmp;
}else if( i < n-1)
return NULL;
while( First->next)
{
First = First->next;
Second = Second->next;
}
ListNode *tmp = Second->next;
Second->next = Second->next->next;
delete tmp;
return head;
}
};