```
public class Solution {
public int remove(ListNode node, int n){
if(node.next == null) return n-1;
int rest = remove(node.next, n);
if(rest == 0){
node.next = (node.next).next;
return -1;
}else
return rest-1;
}
public ListNode removeNthFromEnd(ListNode head, int n) {
return (remove(head, n) == 0)? head.next : head;
}
}
```