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.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public</

本篇博客介绍如何解决LeetCode中的19题,即从链表尾部删除第n个节点。核心是使用双指针在一次遍历中完成任务,特别讨论了如何处理头节点删除的情况。博客分享了两种方法,包括一种两遍历算法和一种优化的一遍过算法。
订阅专栏 解锁全文
500

被折叠的 条评论
为什么被折叠?



