```
public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode dummyHead = new ListNode(-1);
dummyHead.next = head;
calculateLenAndRemove(dummyHead, n);
return dummyHead.next;
}
private int calculateLenAndRemove(ListNode node, int n)
{
if (node == null)
return 0;
int remainingLength = calculateLenAndRemove(node.next, n);
if (remainingLength == n)
node.next = node.next.next;
return remainingLength + 1;
}
}
```