当前位置:网站首页>206.反转链表
206.反转链表
2022-06-11 21:36:00 【爱学代码的学生】
题目描述:
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

方法1:迭代法
代码实现如下:
struct ListNode* reverseList(struct ListNode* head){
//初识条件
if(head==NULL)//条件判断
return NULL;
struct ListNode*p= head->next,*q;
head->next=NULL;//先将原头结点
//结束条件
while(p)
{
q=p->next;//记录下一个改变的结点位置
p->next=head;
head=p;
p=q;
}
return head;
}方法2:头插法
代码实现如下:
struct ListNode*cul=head;
struct ListNode*newnode=NULL;
while(cul){
struct ListNode*next=cul->next;
cul->next=newnode;
newnode=cul;
cul=next;
}
return newnode;边栏推荐
- Usage of esp32c3 Arduino Library
- Leetcode-110-balanced binary tree
- 二分查找 - 学习
- [v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
- 华为设备配置H-VPN
- Redis transaction
- Redis basic data type (list)
- Builder pattern
- LeetCode-76-最小覆盖子串
- EndnoteX9简介及基本教程使用说明
猜你喜欢

Flink error: multiple tasks are started, and only one task is executed
![Analysis on the development history and market development status of China's system integration industry in 2020 [figure]](/img/3c/b53c2a3f59ff6784f128cb98a5a7a2.jpg)
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]

类和对象(1)

Leetcode-322- change exchange

The same efficiency tool for leading enterprises to promote smart finance. Let's have a quick look?

How does the chief financial officer of RPA find the "super entrance" of digital transformation?

如何查看win系统的安装日期

JS performs non empty judgment on various data types of the returned data.

LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)

如何使用事物码 SAT 查找某个 SAPGUI 屏幕字段对应的后台存储数据库表的名称
随机推荐
Look for leap years and see how many leap years I have had since I was born (I have had five)
LeetCode-98-验证二叉搜索树
Diary at 16:29:41 on June 9, 2022
Leetcode-104- maximum depth of binary tree
「大模型」之所短,「知识图谱」之所长
LabVIEW controls Arduino to realize ultrasonic ranging (advanced chapter-5)
LeetCode-129-求根节点到叶节点数字之和
2021 Niuke multi school 5 double strings
Redis data type (string)
CANN编码的一些报错汇编
Expérience 10 génération de courbes bezier - amélioration expérimentale - génération de courbes B - spline par point de contrôle
建造者模式
类和对象(2)
JVM|运行时数据区;程序计数器(PC寄存器);
String copy function
BZOJ3189 : [Coci2011] Slika
LeetCode-155-最小栈
Experiment 10 Bezier curve generation - experiment improvement - control point generation of B-spline curve
How does the chief financial officer of RPA find the "super entrance" of digital transformation?
LeetCode-110-平衡二叉树