当前位置:网站首页>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;
}
边栏推荐
- leetcode:6109. 知道秘密的人数【dp的定义】
- Rich text editing: wangeditor tutorial
- 【云原生】我怎么会和这个数据库杠上了?
- R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用stress.col参数指定强调线的id子集的颜色(色彩)
- Leetcode 61: 旋转链表
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
- sql优化之explain
- Leetcode T49: 字母异位词分组
- STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)
- MySQL的存储过程练习题
猜你喜欢
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
统计php程序运行时间及设置PHP最长运行时间
Real time data warehouse
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
数据仓库面试问题准备
C# wpf 实现截屏框实时截屏功能
失败率高达80%,企业数字化转型路上有哪些挑战?
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
一文概览2D人体姿态估计
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
随机推荐
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
Common content type correspondence table
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
一文概览2D人体姿态估计
R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
Redis daily notes
Mongodb commonly used 28 query statements (forward)
Detailed index of MySQL
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
Opencv3.2 and opencv2.4 installation
LifeCycle
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
瑞吉外卖笔记
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
Test process arrangement (2)