当前位置:网站首页>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 :

边栏推荐
- 普林斯顿微积分读本02第一章--函数的复合、奇偶函数、函数图像
- Nacos introduction and deployment
- @Principle of Autowired annotation
- JVM Lecture 6: how to solve the frequent FGC in online environment?
- LeetCode链表问题——203.移除链表元素(一题一文学会链表)
- 基于遥感解译与GIS技术环境影响评价图件制作
- What are the demand management software for small and medium-sized enterprises
- Nacos registry
- security权限管理详解
- Uniapp applet framework - a set of code, multi segment coverage
猜你喜欢

AXI协议(4):AXI通道上的信号

Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
![Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning](/img/87/9f8353c5c9c700eaa63f66697aa44a.png)
Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning

嵌入式分享合集20

推荐必读:测试人员如何快速熟悉新业务?

Install nccl \ mpirun \ horovod \ NVIDIA tensorflow (3090ti)

MySQL basic learning

域名解析过程全分析,就着文字理解更佳

Common solutions for distributed ID - take one

安装NCCL\mpirun\horovod\nvidia-tensorflow(3090Ti)
随机推荐
New knowledge in big homework
Excel VBA:实现自动下拉填充公式至最后一行
Learn to map with nature medicine -- complex heat map
Ansible tutorial
公交站间的距离 : 简单模拟题
[Luogu] p1383 advanced typewriter
奥特学园ROS笔记--6
Improve reduce parallelism in shuffle operation
Redis过期删除策略和内存淘汰策略
nacos注册中心
阿里云工业视觉智能工程师ACP认证——备考
webassembly 01基本资料
SWAT模型在水文水资源、面源污染模拟中的实践技术
[acwing] 1268. Simple questions
阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
unity场景跳转脚本
Alibaba three sides: how to solve the problems of MQ message loss, duplication and backlog?
新导则下的防洪评价报告编制方法及洪水建模
LeetCode链表问题——203.移除链表元素(一题一文学会链表)