当前位置:网站首页>Leetcode linked list problem - 206. reverse linked list (learn linked list by one question and one article)
Leetcode linked list problem - 206. reverse linked list (learn linked list by one question and one article)
2022-07-26 05:09:00 【18-year-old hates Java】
One 、 Title Description :
Here's the head node of the list head , Please reverse the list , And return the inverted linked list .

Two 、 Code
// Double pointer
class Solution {
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode cur = head;
ListNode temp = null;
while (cur != null) {
temp = cur.next;// Save the next node
cur.next = prev;
prev = cur;
cur = temp;
}
return prev;
}
}3、 ... and 、 Understand linked list
What is a linked list , A linked list is a linear structure connected in series by pointers , Each node consists of two parts , One is the data field and the other is the pointer field ( Holds a pointer to the next node ), The pointer field of the last node points to null( A null pointer means ). The entry node of the link is called the head node of the linked list head.
Single chain list :
Double linked list :
Each node has two pointer fields , One points to the next node , One points to the previous node .
Double linked list You can query forward or backward .

Circular linked list :
Circular linked list , seeing the name of a thing one thinks of its function , The linked list is connected end to end . Circular list can be used to solve the Joseph Ring problem .

How to store linked lists :
Arrays are continuously distributed in memory , But linked lists are not continuously distributed in memory .
The linked list links the nodes in the memory through the pointer of the pointer field .
So the nodes in the linked list are not continuously distributed in memory , It's scattered on some address in memory , The allocation mechanism depends on the memory management of the operating system .

This list starts with 2, The termination node is 7, Each node is distributed in different address spaces of memory , Connected in series by a pointer .
Delete node :
As long as C Node next The pointer Point to E Node is OK .

Add a node :

Compare with array :

边栏推荐
- NPM operation instruction
- Yolov5 implementation process - Directory
- LeetCode链表问题——206.反转链表(一题一文学会链表)
- Practical technology of SWAT Model in simulation of hydrology, water resources and non-point source pollution
- 你对“happen-before原则”的理解可能是错的?
- Several maturity levels of using MES management system
- Shell的read 读取控制台输入、read的使用
- BigDecimal 的 4 个坑,你踩过几个?
- [acwing] 2983. Toys
- npm操作指令
猜你喜欢

【ACWing】1268. 简单题

Date and time function of MySQL function summary

pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0

C语言函数

LeetCode链表问题——203.移除链表元素(一题一文学会链表)

Security permission management details

【ACWing】2983. 玩具

Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month

阿里三面:MQ 消息丢失、重复、积压问题,如何解决?

分布式ID的常用解决方案-一把拿下
随机推荐
BigDecimal 的 4 个坑,你踩过几个?
Ansible tutorial
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
[pytorch] install torch 1.8.1 and check whether torch version and GPU are available
SAP报表开发步骤
YOLOv5执行全过程----目录
ThreadLocal transfer between parent and child threads in asynchronous
CMD operation command
Mathematical modeling and optimization analysis based on general optimization software gams
How to reproduce the official course of yolov5 gracefully (II) -- Mark and train your own data set
[Luogu] p3919 [template] persistent segment tree 1 (persistent array)
Teach you how to use code to realize SSO single sign on
Briefly describe the application fields of WMS warehouse management system
分子骨架跃迁工具-DeLinker介绍
未来大气污染变化模拟
AXI协议(4):AXI通道上的信号
New knowledge in big homework
你对“happen-before原则”的理解可能是错的?
Excel vba: saving multiple worksheets as new files
Redis expiration deletion strategy and memory obsolescence strategy