当前位置:网站首页>LeetCode Algorithm 剑指 Offer 24. 反转链表
LeetCode Algorithm 剑指 Offer 24. 反转链表
2022-06-22 10:10:00 【Alex_996】
题目链接:剑指 Offer 24. 反转链表
Ideas
算法:迭代
数据结构:链表
思路:经典的链表练习题。创建两个指针,一个指向当前遍历的节点cur,另一个指向前一个节点pre,处理的流程就是把当前节点的next指针指向pre节点,然后pre指针再指向cur节点,cur再指向原本当前节点指向的下一个节点。
Code
C++
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode *pre = nullptr, *cur = head;
while (cur != nullptr) {
ListNode *nxt = cur->next;
cur->next = pre;
pre = cur;
cur = nxt;
}
return pre;
}
};
边栏推荐
- APM 飞行模式切换--源码详解
- Attack and defense world web practice area beginner level
- [untitled] repair log
- Some penetration test terms I collected
- 一句话木马上传常见的几种方法
- Advanced Web Zone record of attack and defense world (I)
- After using Matplotlib for so long, I didn't know that the data could move
- 工作中的帕累托定律:关注结果,而不是输出
- 6-32 construction of linked list by header insertion method
- 快速掌握 ASP.NET 身份认证框架 Identity - 登录与登出
猜你喜欢

HMS core news industry solution: let technology add humanistic temperature

Don't be silly enough to distinguish hash, chunkhash and contenthash

加密市场暴跌,stETH引发新一轮担忧

MYSQL Skip Scan Range 小功能,解决大问题 ?

thinkphp5.0.24反序列化漏洞分析

2022-06-09 work record --yarn/npm-error-eperm: operation not permitted, UV_ cwd

IPO配置指南

The future of Dao: an organization primitive for building Web3

Read the history of it development in one breath

Signal integrity (SI) power integrity (PI) learning notes (XXIV) differential pair and differential impedance (IV)
随机推荐
快速掌握 ASP.NET 身份认证框架 Identity - 登录与登出
Solend废止「接管巨鲸」提案 清算「炸弹」未除
数据智能基础设施升级窗口将至?看九章云极 DingoDB 如何击破数据痛点
Former amd chip architect roast said that the cancellation of K12 processor project was because amd counseled!
《网络安全等级保护基本要求》(GBT 22239-2019)标准解读
When golang operates mongodb, vscode prompts primitive E composite literal uses unlocked fields
IPO Configuration Guide
字节二面:Redis主节点的Key已过期,但从节点依然读到过期数据是为什么?怎么解决?
px4代码学习之基于uavcan协议的时间同步消息中添加自定义字段
It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines
Cobalt Strike 从入门到入狱(三)
软件项目管理 8.3.敏捷项目质量活动
The ruby code in logstash converts the @timestamp timestamp format
Tiktok practice ~ personal Center
What kind of experience is middle-aged unemployment
Software project management 8.3 Agile project quality activities
Target detection / segmentation training using pytorch mask RCNN
Summary of neural network training trick
[popular science] to understand supervised learning, unsupervised learning and reinforcement learning
Error in PHP installation of Pagoda: libcares so. 2: cannot open shared object file: No such file or directory