import java.util.*;

/*

  • public class ListNode {
  • int val;
  • ListNode next = null;
  • } */

public class Solution { /** * * @param head ListNode类 * @param n int整型 * @return ListNode类 */ public ListNode removeNthFromEnd (ListNode head, int n) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode pre = dummy; ListNode post = dummy; for(int i = 0;i <= n;i++){ pre = pre.next; } while(pre != null){ pre = pre.next; post = post.next; } ListNode temp = post.next; post.next = temp.next;

    return dummy.next;
    // write code here
}

}