package code;
/*
* 19. Remove Nth Node From End of List
* n
* Medium
* Linked List, Two Pointers
*
* nn
*/
public class lc19 {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode low = new ListNode(0);
ListNode fast = new ListNode(0);
ListNode res = low;
low.next = head;
fast.next = head;
while(n>0){
fast = fast.next;
n--;
}
while(fast.next!=null){
low = low.next;
fast = fast.next;
}
ListNode temp = low.next.next;
low.next = temp;
return res.next;
}
public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
}