@@ -0,0 +1,1056 @@
+package removeNthNodeFromEndOfList;%0A%0A/**%0A * Given a linked list, remove the nth node from the end of list and return its head.%0A * %09For example,%0A * %09%09Given linked list: 1-%3E2-%3E3-%3E4-%3E5, and n = 2.%0A * %09%09After removing the second node from the end, the linked list becomes 1-%3E2-%3E3-%3E5.%0A * %0A * @author Yang%0A */%0A%0Aclass ListNode%7B%0A%09int val;%0A%09ListNode next;%0A%09ListNode(int x)%7B%0A%09%09val = x;%0A%09%7D%0A%7D%0A%0Apublic class Solution %7B%0A    public ListNode removeNthFromEnd(ListNode head, int n) %7B%0A        if(head == null) return null;%0A        if(n %3C 1) return head;%0A        ListNode prehead = new ListNode(0);%0A        prehead.next = head;%0A        ListNode fast = head;%0A        %0A        while(n %3E 0)%7B%0A            if(fast == null) return head;%0A            fast = fast.next;%0A            n--;%0A        %7D%0A        %0A        ListNode slow = prehead;%0A        while(fast != null)%7B%0A            fast = fast.next;%0A            slow = slow.next;%0A        %7D%0A        %0A        ListNode temp = slow.next;%0A        slow.next = temp.next;%0A        temp.next = null;%0A        %0A        return prehead.next;%0A    %7D%0A%7D

remove nth node from end of list