@@ -0,0 +1,1104 @@
+// Given a linked list, remove the nth node from the end of list and return its head.%0A%0A// For example,%0A%0A//    Given linked list: 1-%3E2-%3E3-%3E4-%3E5, and n = 2.%0A%0A//    After removing the second node from the end, the linked list becomes 1-%3E2-%3E3-%3E5.%0A// Note:%0A// Given n will always be valid.%0A// Try to do this in one pass.%0A%0A/**%0A * Definition for singly-linked list.%0A * public class ListNode %7B%0A *     int val;%0A *     ListNode next;%0A *     ListNode(int x) %7B%0A *         val = x;%0A *         next = null;%0A *     %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public ListNode removeNthFromEnd(ListNode head, int n) %7B%0A    %09if(head == null) return head;%0A%0A    %09ListNode fast = head;%0A    %09ListNode slow = null;%0A%0A    %09int step = n - 1;%0A%0A    %09while(step %3E= 0)%7B%0A    %09%09fast = fast.next;%0A    %09%09step--;%0A    %09%7D%0A// %7B1,2%7D  1%0A// %7B1,2%7D  2%0A    %09while(fast != null)%7B%0A    %09%09fast = fast.next;%0A    %09%09if(fast != null)%7B%0A    %09%09%09if(slow == null)%7B%0A    %09%09%09%09slow = head;%0A    %09%09%09%7Delse%7B%0A%09    %09%09%09slow = slow.next;%0A    %09%09%09%7D%0A    %09%09%7D%0A    %09%7D%0A%0A    %09if( slow == null )%7B%0A    %09%09return head.next;%0A    %09%7D%0A%0A    %09slow.next = slow.next.next;%0A%0A    %09return head;%0A    %7D%0A%7D

add remove nth node from end of list solution