当前位置:网站首页>剑指Offer | 链表转置
剑指Offer | 链表转置
2022-06-28 09:16:00 【小雅痞】
链表转置 {1,2,3} -> {3,2,1}
给定一个单链表的头结点head,长度为n,反转该链表后,返回新链表的表头。
public class Solution{
public ListNode ReverseList(ListNode head){
if(head == null){
return null;
}
ListNode pre = null;
ListNode next = head.next;
while(head != null){
// 局部反转
head.next = pre;
// pre head 都向前移动一格
pre = head;
head = next;
//如果head不为空,继续记录next
if(head !=null){
next = head.next;
}
}
// 到达链表末尾,此时 1<--2<--3(pre) head = null;
return pre;
}
你一句春不晚,我就到了真江南。
边栏推荐
- Quickly understand JVM structure and working principle
- 1. Kimball dimension modeling of data warehouse: what is a fact table?
- When the interviewer asks you to write binarysort in two ways
- For the development of short video app, the elder warned me to choose the open source code
- 图解MySQL的binlog、redo log和undo log
- Analysis of prepaid power purchase device
- Basic operation of PMP from applying for the exam to obtaining the certificate, a must see for understanding PMP
- Is it safe to open an account for online stock speculation?
- Power data
- Edit the live broadcast source code with me. How to write the live broadcast app code
猜你喜欢

From knowledge to wisdom: how far will the knowledge map go?

Use of Jasper soft studio report tool and solution of thorny problems

new URL(“www.jjj.com“)

買賣股票費用計算

STL -- binder

Static page of pinyougou mall

Basic knowledge of hard disk (head, track, sector, cylinder)

Why does select * lead to low query efficiency?

Application of current limiting protector in preventing electrical fire in shopping malls

new URL(“www.jjj.com“)
随机推荐
Stock suspension
Implementation of single sign on
APICloud携手三六零天御,助力企业守好App安全“第一关”
Protection range and optimization of motor protector for hoist equipment
A strange execution plan. One table in the association query is not associated with any other tables
Container adapter - stack: stack queue: queue priority_ Queue: priority queue
How to solve the problem of port number occupation
[ybtoj advanced training guide] maximum separation [hash] [Floyd]
Edit the live broadcast source code with me. How to write the live broadcast app code
Learn how Alibaba manages the data indicator system
Rich text - Test Case
全链路业务追踪落地实践方案
1182:合影效果
DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
1181:整数奇偶排序
数据挖掘建模实战
[big case] Xuecheng online website
Android studio interview preparation
Power data
RMAN backup message ora-19809 ora-19804