欢迎24级新生

2102. LeetCode Remove Nth Node From End of List

删除链表中倒数第 n 个结点。

输入

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.

提示

设置 2 个指针,⼀个指针距离前⼀个指针 n 个距离。同时移动 2 个指针,2 个指针都移动相同的距离。当⼀个指针移动到了终点,那么前⼀个指针就是倒数第 n 个节点了。

登录以提交代码。
单点时限 1 秒
内存限制 128 MB
提交 0
通过 0