public ListNode removeNthFromEnd(ListNode head, int n) {
// Start typing your Java solution below
// DO NOT write main() function
ListNode fast = head;
ListNode slow = head;
int i = 1;
for(;i<=n&&fast.next!=null;i++) fast = fast.next;
if(i==n) return head.next;
while(fast.next!=null){
slow = slow.next;
fast = fast.next;
}
slow.next = slow.next.next;
return head;
}