当前位置:网站首页>Linked list: reverse linked list
Linked list: reverse linked list
2022-06-13 02:45:00 【Zeng Qiang】
List of articles
subject
https://leetcode-cn.com/problems/UHnkqh/
Their thinking
Reverse the linked list , You can use double pointers pre and cur To solve .
It should be noted that :
- pre Pointer to null node ,cur Point to the head node .
- In exchange for pre and cur When you're pointing , Temporary storage required cur Of next node .
During backward traversal of the pointer , In exchange for cur.next = pre. So as to complete the inversion of the linked list . The specific steps are as follows :
Code
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */
class Solution {
public ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode cur = head;
while(cur != null) {
ListNode temp = cur.next;
cur.next = pre;
pre = cur;
cur = temp;
}
return pre;
}
}
summary
Reverse a linked list , It mainly focuses on how to exchange the pointers of two linked lists , At the same time, cache the next node first , To continue traversing the linked list . This problem can be solved with double pointers .
边栏推荐
- Huffman tree and its application
- [data analysis and visualization] key points of data drawing 11- precautions for radar chart
- Leetcode 926. Flip string to monotonically increasing [prefix and]
- 微信云开发粗糙理解
- 遍历数组,删除某元素,直到删除为止
- [reading papers] visual convolution zfnet
- Resource arrangement
- 01 初识微信小程序
- C # illustrated tutorial (Fourth Edition) chapter7-7.2 accessing inherited members
- [data analysis and visualization] key points of data drawing 6- too many data groups
猜你喜欢

Open source video recolor code

Detailed explanation of handwritten numeral recognition based on support vector machine (Matlab GUI code, providing handwriting pad)

Logiciel professionnel de gestion de base de données: Valentina Studio Pro pour Mac

The latest Matlab r2020 B ultrasonic detailed installation tutorial (with complete installation files)

Matlab: obtain the figure edge contour and divide the figure n equally

Vant框架中关于IndexBar索引栏的CDN单页面引用,无法正常展示

03 recognize the first view component

Principle and steps of principal component analysis (PCA)
![[data analysis and visualization] key points of data drawing 4- problems of pie chart](/img/e1/618ff53b33b4b1de6acf4942130c17.jpg)
[data analysis and visualization] key points of data drawing 4- problems of pie chart

Special topic I of mathematical physics of the sprint strong foundation program
随机推荐
Opencv 15 face recognition and eye recognition
Ijkplayer source code - setting options
Multiple knapsack problem
How to destroy a fragment- How to destroy Fragment?
redis. Conf general configuration details
Detailed explanation of handwritten numeral recognition based on support vector machine (Matlab GUI code, providing handwriting pad)
The precision of C language printf output floating point numbers
Traverse the array and delete an element until it is deleted
小程序 input,textarea组件权重比fixed的z-index都高
[data analysis and visualization] key points of data drawing 8- use of circular bar chart
Ijkplayer source code ---packetqueue
Linear, integer, nonlinear, dynamic programming
Sans certificate generation
專業的數據庫管理軟件:Valentina Studio Pro for Mac
[data and Analysis Visualization] D3 introductory tutorial 2- building shapes in D3
在IDEA使用C3P0連接池連接SQL數據庫後卻不能顯示數據庫內容
Matlab: find the inner angle of n-sided concave polygon
Prometheus node_exporter安装并注册为服务
PCR validation of basic biological experiments in [life sciences]
05 tabbar navigation bar function