package linkedList;

/**
 * Created by cuixiaodao on 12/23/2017
 * for leetCode problem:
 * https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/
 */

public class RemoveNthNode{
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode first = head, second = head;        
                
        while(n-- > 0) first = first.next;
        
        if(first == null) return head.next;

        while(first.next != null){
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        return head;
    }    
}
@@ -255,16 +255,75 @@
 nt n) %7B%0A
+        // %E4%BB%A4first, second%E8%B7%9D%E7%A6%BB%E4%B8%BAn,first%E5%88%B0%E8%BE%BE%E9%93%BE%E8%A1%A8%E6%9C%AB%E5%B0%BE%E6%97%B6%EF%BC%8Csecond%E5%AF%BC%E5%88%B0%E5%80%92%E6%95%B0%E7%AC%ACn%E4%B8%AA%E8%8A%82%E7%82%B9%0A
         
@@ -665,8 +665,9 @@
  %7D    %0A%7D
+%0A

Update RemoveNthNode.java