当前位置:网站首页>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;
}
}
边栏推荐
- 72. 编辑距离
- 【TA-霜狼_may-《百人计划》】1.1 渲染流水线
- [TA frost wolf \u may- hundred people plan] 1.3 secret of texture
- Browser top loading (from Zhihu)
- 10. regular expression matching
- 30. Concatenate substrings of all words
- [ta- frost wolf \u may- hundred people plan] 2.2 model and material space
- mysql 函数 变量 存储过程
- 168. excel table column name
- JMeter学习笔记2-图形界面简单介绍
猜你喜欢
Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
【人话版】WEB3黑暗森林中的隐私博弈
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
The programmer's girlfriend gave me a fatigue driving test
JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
多次跳槽后,月薪等于老同事的年薪
Go learning --- unit test subtest
随机推荐
Future of NTF and trends in 2022
Grid system in bootstrap
JMeter login failure, extracting login token, and obtaining token problem solving
166. fractions to decimals
线程常用方法与守护线程
多次跳槽后,月薪等于老同事的年薪
高并发下接口幂等性如何保证?
PageObject模式解析及案例
LeetCode 1400. Construct K palindrome strings
[shortcut key]
PageObject模式解析及案例
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
Valid @suppresswarnings warning name
LeetCode 1399. Count the maximum number of groups
392. 判断子序列
165. compare version numbers
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET