/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* empty = new ListNode(-1);
empty->next = head;
ListNode* slow = empty, *fast = empty;
for(int i=0;i<n;i++){
fast = fast->next;
}
while(fast->next){
slow = slow->next;
fast = fast->next;
}
slow->next = slow->next->next;
return empty->next;
}
};