当前位置:网站首页>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;
}
边栏推荐
- 92.(cesium篇)cesium楼栋分层
- What is the real meaning and purpose of doing things, and what do you really want
- 商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
- Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
- [matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
- sharding key type not supported
- 一文概览2D人体姿态估计
- nowcoder重排链表
- opencv3.2 和opencv2.4安装
- 瑞吉外卖笔记
猜你喜欢

Learn kernel 3: use GDB to track the kernel call chain

聊聊保证线程安全的 10 个小技巧

Rich text editing: wangeditor tutorial

基于51单片机的超声波测距仪

C# wpf 实现截屏框实时截屏功能

codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】

Why should Base64 encoding be used for image transmission

Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?

MATLAB中tiledlayout函数使用

实时数据仓库
随机推荐
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
按照功能对Boost库进行分类
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
Opencv3.2 and opencv2.4 installation
海外游戏代投需要注意的
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
C# wpf 实现截屏框实时截屏功能
TestSuite and testrunner in unittest
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
sql优化之explain
ViewModel 初体验
第十七章 进程内存
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
sql优化之查询优化器
leetcode:6109. 知道秘密的人数【dp的定义】
ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
Test process arrangement (3)
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
为什么图片传输要使用base64编码
数据湖(十三):Spark与Iceberg整合DDL操作