当前位置:网站首页>Nowcoder reverse linked list
Nowcoder reverse linked list
2022-07-04 14:24:00 【Fan Qianzhi】
describe
Given the head node of a single linked list pHead( The header node has a value , For example, in the figure below , its val yes 1), The length is n, After reversing the linked list , Return the header of the new linked list .
Data range : 0 ≤ n ≤ 10000 0\leq n\leq10000 0≤n≤10000
requirement : Spatial complexity O(1), Time complexity O(n).
For example, when entering a linked list {1,2,3} when ,
After reversal , The original linked list becomes {3,2,1}, So the corresponding output is {3,2,1}.
The above conversion process is shown in the figure below :

Ideas
Reverse the linked list with recursive method .
Code
public ListNode ReverseList(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode reverse = ReverseList(head.next);
head.next.next = head;
head.next = null;
return reverse;
}
边栏推荐
- The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
- Real time data warehouse
- R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
- 92.(cesium篇)cesium楼栋分层
- R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
- 2022游戏出海实用发行策略
- MySQL的存储过程练习题
- sharding key type not supported
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
- gin集成支付宝支付
猜你喜欢

Data warehouse interview question preparation

为什么图片传输要使用base64编码
![去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]
![去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]

【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法

使用CLion编译OGLPG-9th-Edition源码

富文本编辑:wangEditor使用教程

The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?

RK1126平台OSD的实现支持颜色半透明度多通道支持中文

Rich text editing: wangeditor tutorial
随机推荐
Oppo find N2 product form first exposure: supplement all short boards
瑞吉外卖笔记
第十七章 进程内存
DDD application and practice of domestic hotel transactions -- Code
leetcode:6109. 知道秘密的人数【dp的定义】
vscode 常用插件汇总
Xcode 异常图片导致ipa包增大问题
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
LifeCycle
ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
Use of arouter
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
R language uses the mutation function of dplyr package to standardize the specified data column (using mean function and SD function), and calculates the grouping mean of the standardized target varia
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
What is the real meaning and purpose of doing things, and what do you really want
Learn kernel 3: use GDB to track the kernel call chain
Opencv3.2 and opencv2.4 installation
卷积神经网络经典论文集合(深度学习分类篇)