Given a linked list, remove the n-th node from the end of list and return its head. 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 w…
给定一个链表,删除链表的倒数第 n 个节点并返回头结点.例如,给定一个链表: 1->2->3->4->5, 并且 n = 2.当删除了倒数第二个节点后链表变成了 1->2->3->5.详见:https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/ 思路:设置两个指针first跟second.first指针先移动n步,若此时first指针为空,则表示要删除的是头节点,此时直…
这道题是LeetCode里的第19道题. 题目要求: 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 1->2->3->5. 说明: 给定的 n 保证是有效的. 进阶: 你能尝试使用一趟扫描实现吗? 先求链表长度的暴力法我就不讲了. 关于一趟实现的办法就是先让 back 先走 n 次,此时 front 和 back 产生了长度为 n 的间…
Given a linked list, remove the n-th node from the end of list and return its head. 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 w…
Level: Medium 题目描述: Given a linked list, remove the n-th node from the end of list and return its head. 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-…