class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
if(head == null || n == 0) return head;
ListNode d = new ListNode(-1);
d.next = head;
ListNode f = d;
ListNode s = d;
while(n>0){
f = f.next;
n--;
}
while(f.next != null){
f = f.next;
s = s.next;
}
s.next=s.next.next;
return d.next;
}
}