当前位置:网站首页>19. 删除链表的倒数第 N 个结点
19. 删除链表的倒数第 N 个结点
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:19. 删除链表的倒数第 N 个结点
描述:给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。
解题思路
1、可以用数组存储链表节点;
2、用双指针,见代码;
原代码##
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode *p = head;
ListNode *slow = head;
ListNode *fast = head;
for (int i = 0; i < n; ++i) {
fast = fast->next;
}
if (!fast) return slow->next;
while (fast->next) {
slow = slow->next;
fast = fast->next;
}
slow->next = slow->next->next;
return p;
}
};
边栏推荐
- SAP ABAP data types and data objects
- Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
- Standardized compilation knowledge
- SAP ABAP internal table classification, addition, deletion, modification and query
- PHP solves Chinese display garbled code
- Cron expressions in scheduled tasks
- 【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程
- Installation (detailed illustration) and use of SVN
- String类为何final修饰
- 光伏板怎么申请ASTM E108阻燃测试?
猜你喜欢
随机推荐
Matlab learning 9- nonlinear sharpening filter for image processing
SAP abap 数据类型与数据对象
Codeworks round 680 div2
K8s application (IV) - build a redis5 cluster (for direct external access)
EN 45545-2:2020 T11烟毒性检测
SQL基本查询
Classical graph theory, depth first and breadth first, topology, prim and krukal, it's time to review
马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup
EN 45545 R24氧指数测试方法解析
GCC AVR(Atmel Studio+ AVR Studio)如何将结构体数组定义在程序存储器(flash)空间并进行读操作
Sword finger offer 10- ii Frog jumping on steps
String类为何final修饰
vagrant 安装踩坑
Analysis of EN 45545 R24 oxygen index test method
CMVSS TSD No. 302与49 CFR 571.302测试方法是否一样
Android interview transcript (carefully sorted out)
端口占用问题,10000端口
Standardized compilation knowledge
typescript高阶特性一 —— 合并类型(&)
Type of SQL command (incomplete)








