当前位置:网站首页>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 _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
- 30. Concatenate substrings of all words
- Qt开发经验小技巧226-230
- Loop filtering based on Unet
- MallBook:后疫情时代下,酒店企业如何破局?
- How keil displays Chinese annotations (simple with pictures)
- Do280 management application deployment --rc
- [today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
- JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
- Jenkins automatically cleans up construction history
猜你喜欢

Promql select time series
![[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

Use of JMeter counters

25.k sets of flipped linked lists

京东智能客服言犀意图体系搭建和意图识别技术介绍

The programmer's girlfriend gave me a fatigue driving test
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

陈宇(Aqua)-安全->云安全->多云安全

Spock单元测试框架介绍及在美团优选的实践___第一章

MallBook:后疫情时代下,酒店企业如何破局?
随机推荐
This may be your last chance to join Tencent
Embedded System Development Notes 81: Using Dialog component to design prompt dialog box
166. fractions to decimals
Common thread methods and daemon threads
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
168. excel table column name
Millet College wechat scanning code login process record and bug resolution
NFT:使用 EIP-2981 開啟 NFT 版稅之旅
HoloLens2开发环境搭建及部署app
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
浏览器顶部loading(来自知乎)
Volley parsing data shows networking failure
LeetCode 1828. Count the number of points in a circle
程序员女友给我做了一个疲劳驾驶检测
Qt开发经验小技巧226-230
跳槽一次涨8k,5年跳了3次...
25.K个一组翻转链表
Do280 management application deployment --rc
[TA frost wolf \u may - "hundred people plan"] 2.1 color space