当前位置:网站首页>206. reverse linked list
206. reverse linked list
2022-07-01 04:05:00 【Sit at a sunny window and drink tea alone】

Train of thought Change pointer direction

Main idea : Traverse all nodes , Change the direction of the node
- The initial state : last Point to null, head Point to the head node

- Define a nextHead node , Used to store head.next The node of , Otherwise, once the direction changes , head.next The node is lost

- Then change head Direction of edges of , head.next = last

- last and head Move forward one step

- Then cycle the above process
class Solution {
public ListNode reverseList(ListNode head) {
ListNode last = null;
while(head != null) {
// preservation head.next , as a result of When the direction of the edge changes , head.next Nodes of will be lost , So save it in advance
ListNode nextHead = head.next;
// Change the direction of the edge
head.next = last;
// last and head Move forward one step
last = head;
head = nextHead;
}
return last;
}
}
边栏推荐
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
- All in one 1086: Jiaogu conjecture
- Coinbase in a bear market: losses, layoffs, stock price plunges
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- [untitled] Li Kou 496 Next larger element I
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- 嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
- Web components series (VIII) -- custom component style settings
- [TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation
- 【无标题】
猜你喜欢

Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages

NFT:使用 EIP-2981 开启 NFT 版税之旅

HoloLens2开发环境搭建及部署app
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle

互联网行业最佳产品开发流程 推荐!

采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势

【TA-霜狼_may-《百人计划》】2.1 色彩空间
![[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation](/img/49/173b1f1f379faa28c503165a300ce0.png)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation

Loop filtering based on Unet
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
随机推荐
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
京东智能客服言犀意图体系搭建和意图识别技术介绍
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
206.反转链表
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
6. Z 字形变换
Browser top loading (from Zhihu)
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
Volley parsing data shows networking failure
Redis (VII) optimization suggestions
166. fractions to decimals
【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
Common thread methods and daemon threads
409. longest palindrome
Qt开发经验小技巧226-230
PageObject模式解析及案例
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
[send email with error] 535 error:authentication failed
25.K个一组翻转链表