当前位置:网站首页>Leetcode algorithm refers to offer 24 Reverse linked list
Leetcode algorithm refers to offer 24 Reverse linked list
2022-06-22 10:57:00 【Alex_ 12 hours a day 6 days a week】
Topic link : The finger of the sword Offer 24. Reverse a linked list
Ideas
Algorithm : iteration
data structure : Linked list
Ideas : Classic linked list exercises . Create two pointers , A node that points to the current traversal cur, The other one points to the previous node pre, The processing flow is to transfer the current node's next Pointer to pre node , then pre Pointer pointing again cur node ,cur Then point to the next node to which the current node originally points .
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;
}
};
边栏推荐
- LeetCode Algorithm 剑指 Offer 24. 反转链表
- npm install 命令的介绍
- 大学生期末考试SQL语句
- PHP website, how to achieve the function of batch printing express orders?
- 外贸专题:外贸邮件营销模板
- Introduction to NPM install command
- 今天,SysAK 是如何实现业务抖动监控及诊断?&手把手带你体验Anolis OS|第25-26期
- 2022年深入推进IPv6部署和应用,该如何全面实现安全升级改造?
- Batch create / delete files, folders, modify file name suffixes
- MySQL使用SQL语句修改字段长度、字段名称
猜你喜欢

Zero‐Copy API

Inftnews | view: market cooling or opportunities for NFT applications

HMS Core新闻行业解决方案:让技术加上人文的温度

The data intelligence infrastructure upgrade window is approaching? See Chapter 9 how Yunji dingodb breaks through data pain points

Pule frog 5D flying cinema 5D dynamic cinema experience hall equipment 7d multi person interactive cinema

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

Ones attends the first "Lean Software Engineering Conference" to share performance improvement practices

世界上第一个“半机械人”去世,改造自己只为“逆天改命”
Recommander un logiciel de machine virtuelle pour la construction rapide d'un Cluster d'ordinateurs à puce M1

Backbone! Youxuan software was selected as one of the top 100 digital security companies in China in 2022
随机推荐
【jenkins】shell脚本调jenkins api接口
WordPress like hooks and filters in laravel
Path Join() and path The difference between resolve()
LeetCode Algorithm 21. 合并两个有序链表
Go微服务(一)——RPC入门
外贸专题:外贸邮件营销模板
数据库课程虚拟教研室负责人杜小勇:立足国产数据库重大需求,探索课程体系建设新模式
本周四晚19:00战码先锋第7期直播丨三方应用开发者如何为开源做贡献
scrapy. Transfer of meta parameter data of request()
线程常用调度方法
2022陕西省安全员B证操作证考试题库及在线模拟考试
[graduation season · advanced technology Er] youth never ends
社恐?自我介绍时大脑一片空白?
In 2022, IPv6 deployment and application will be further promoted. How can we comprehensively realize security upgrading and transformation?
Use of libevent
Niuke.com Huawei question bank (31~40)
交换类排序法
Laravel development article URL generator
字节三面:到底知不知道什么是Eureka?
Native JS dynamically add and delete classes