@@ -0,0 +1,2206 @@
+package main.algorithm.leetcode;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Title : main.algorithm.leetcode %3Cbr%3E%0A * Description :%0A *   %3CP%3E Runtime: 0 ms, faster than 100.00%25 of Java online submissions for Remove Nth Node From End of List.%0A *   %3CP%3E Memory Usage: 34.8 MB, less than 100.00%25 of Java online submissions for Remove Nth Node From End of List.%0A * @author chile%0A * @version 1.0%0A * @date 2019/8/21 11:21%0A */%0Apublic class RemoveNthFromEnd %7B%0A%0A    public class ListNode %7B%0A%0A        int val;%0A%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    class Solution %7B%0A        public ListNode removeNthFromEnd(ListNode head, int n) %7B%0A            ListNode tempNode = head, prevNode = null, nextNode = null;%0A%0A            int length = 0;%0A            while (tempNode != null) %7B%0A                length++;%0A                tempNode = tempNode.next;%0A            %7D%0A%0A            int index = length - n;%0A%0A            if (index == 0) %7B%0A                return head.next;%0A            %7D else %7B%0A                tempNode = head;%0A                for (int i = 0; i %3C length; i++) %7B%0A                    if (i == index - 1) %7B%0A                        prevNode = tempNode;%0A                    %7D%0A                    if (i == index) %7B%0A                        prevNode.next =  tempNode.next;%0A                        break;%0A                    %7D%0A                    tempNode = tempNode.next;%0A                %7D%0A            %7D%0A%0A            return head;%0A        %7D%0A    %7D%0A%0A    private ListNode createList() %7B%0A        ListNode n1 = new ListNode(1);%0A        ListNode n2 = new ListNode(2);%0A        ListNode n3 = new ListNode(3);%0A        ListNode n4 = new ListNode(4);%0A        ListNode n5 = new ListNode(5);%0A%0A        n1.next = n2;%0A        n2.next = n3;%0A        n3.next = n4;%0A        n4.next = n5;%0A%0A        return n1;%0A    %7D%0A%0A    @Test%0A    public void test1() %7B%0A%0A        for (int i = 1; i %3C 6; i++) %7B%0A            System.out.print(%22nth is: %22 + i + %22, result: %22);%0A            ListNode head = new Solution().removeNthFromEnd(createList(), i);%0A            while (head != null) %7B%0A                System.out.print(head.val);%0A                head = head.next;%0A            %7D%0A            System.out.println();%0A        %7D%0A    %7D%0A%0A%7D%0A

Remove Nth Node From End of List