# LeetCode-remove-nth-node-from-end-of-list

## 题目描述

Given a linked list, remove the nth node from the end of list and return its head.

For example,

   Given linked list: 1->2->3->4->5, and n = 2.

After removing the second node from the end, the linked list becomes 1->2->3->5.


Note:
Given n will always be valid.

Try to do this in one pass.

/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) {
*         val = x;
*         next = null;
*     }
* }
*/
public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode flag = new ListNode(0);
ListNode pre = flag;
pre.next = slow;
for(int i=1; i<n; i++){
fast = fast.next;
}
while(fast.next != null) {
fast = fast.next;
slow = slow.next;
pre = pre.next;
}
pre.next = slow.next;
return flag.next;
}
}

/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) {
*         val = x;
*         next = null;
*     }
* }
*/
public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {

ListNode pre = new ListNode(0);

ListNode predelete = pre;
for(int i=0; i<n; i++){
return null;
}
}
predelete = predelete.next;
}
predelete.next = predelete.next.next;
return pre.next;
}
}

#### [LeetCode] 019. Remove Nth Node From End of List (Easy) (C++/Python)

2015-03-04 19:26:10

#### remove-nth-node-from-end-of-list

2018-01-04 21:00:57

#### LeetCode 19 — Remove Nth Node From End of List（C++ Java Python）

2014-02-23 12:00:32

#### leetcode-Remove Nth Node From End of List

2014-11-27 02:14:07

#### 【leetcode】Remove Nth Node From End of List

2014-08-28 16:58:19

#### LeetCode:Remove Nth Node From End of List

2014-11-18 10:08:28

#### leetcode--remove-nth-node-from-end-of-list(移除链表中的倒数第N个节点)

2018-06-26 10:51:11

#### Remove Nth Node From End of List

2014-09-11 19:58:01

#### LeetCode 19. Remove Nth Node From End of List 解题报告

2016-02-20 14:58:48

#### leetcode笔记--Remove Nth Node From End of List

2016-02-19 14:13:23