当前位置:网站首页>Likou Brush Question Record 8.1-----206. Reverse linked list
Likou Brush Question Record 8.1-----206. Reverse linked list
2022-08-09 02:02:00 【@ Bai Gui】
一、题目


二、代码
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
ListNode* reverseList(ListNode* head) {
//题目分析:
//Unified linked list format
ListNode* dummyhead = new ListNode(0); //Set a fake header node In order to unify the single-node and multi-node situations
dummyhead->next = head;
//current and previous
ListNode* first_node = new ListNode(0);
first_node=head;
ListNode* second_node = new ListNode(0);
second_node=head;
ListNode* temp_node = new ListNode(0);
temp_node=nullptr;
if(head!=nullptr)
temp_node=head->next;
//第一个节点指向空
if(head!=nullptr)
head->next=nullptr;
// Node for stepping Nodes and pointers are still different
while(temp_node!=nullptr)
{
first_node=temp_node;
temp_node=first_node->next; //before the last steptemp都记录
std::cout<<" second1 "<<second_node->val<<std::endl;
first_node->next=second_node;
second_node=first_node;
std::cout<<" first "<<first_node->val<<std::endl;
std::cout<<" second2 "<<second_node->val<<std::endl;
}
// ListNode *show_node;
// show_node=first_node; //Construct a display node
// while(show_node->next!=nullptr)
// {
// std::cout<<" "<<show_node->val<<" ";
// show_node=show_node->next;
// }
// std::cout<<" "<<show_node->val<<" "; //打印最后一个
// std::cout<<" "<< std::endl;
return first_node;
}
};
三、运行结果

边栏推荐
- ONNX是什么?怎么用?[简明解读版]
- eladmin容器部署超详细过程
- OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
- PostMan import certificate add certificate
- 线段树知识整理
- Latex example reference
- [Signal denoising] Based on Sage-Husa adaptive Kalman filter to realize the suppression of ocean wave magnetic field noise and the generation of ocean wave magnetic field noise with matlab code
- 『Another Redis DeskTop Manager』用了这款Redis可视化工具,分析效率提升12倍
- 配置文件的读取-TOML
- D. Tournament Countdown
猜你喜欢

ICMP差错报告报文数据字段

Group DETR:分组一对多匹配是加速DETR收敛的关键
![class path resource [bean.xml] cannot be opened because it does not 错误解决方案](/img/e2/6430a511998944a3357984b554b00c.png)
class path resource [bean.xml] cannot be opened because it does not 错误解决方案

MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor

如何在群晖系统中安装cpolar(群晖6.X版)

LeetCode每日两题01:二分查找 (均1200道)

Proe/Creo智能硬件产品结构设计要点「干货分享」

数字孪生+燃气管理,开启智慧燃气管理新模式

力扣刷题记录4.1-----209. 长度最小的子数组

力扣刷题记录5.1-----59. 螺旋矩阵 II
随机推荐
LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
UsernameAuthenticationFilter授权成功后调用AuthenticationSuccessHandler时的解析
Latex example reference
2022PMP项目管理认证考试报考指南(1)
【Unity】判断鼠标是否点击在UI上
2020.12.4日志
2022 PMP Project Management Certification Exam Registration Guide (1)
Observer pattern
使用百度EasyDL实现智能垃圾箱
力扣刷题记录7.1-----707. 设计链表
[机缘参悟-65]:《兵者,诡道也》-6-孙子兵法解读-并战计
如何在EasyDSS中使用ffmpeg实现点播视频的拼接与合成?
Go-11-流程控制
HCIP-R&S By Wakin自用笔记(2)OSPF之OSPF回顾、虚连接
Using ngrok on Raspberry Pi (Extra 2)
力扣刷题记录4.1-----209. 长度最小的子数组
33. 分别谈谈联合索引生效和失效的条件
Go-11 - Process Control
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
《LC刷题总结》——贪心