当前位置:网站首页>反转链表练习
反转链表练习
2022-04-23 06:26:00 【笔描相思】
var reverseList = function(head) {
// 判断下变量边界问题
if (!head || !head.next) return head
// 初始设置为空,因为第一个节点反转后就是尾部,尾部节点指向 null
let pre = null
let current = head
let next
// 判断当前节点是否为空
// 不为空就先获取当前节点的下一节点
// 然后把当前节点的 next 设为上一个节点
// 然后把 current 设为下一个节点,pre 设为当前节点
while(current) {
next = current.next
current.next = pre
pre = current
current = next
}
return pre
};
版权声明
本文为[笔描相思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44788119/article/details/120902873
边栏推荐
猜你喜欢
Reflection on the systematic design of Android audio and video caching mechanism
BTree、B+Tree和HASH索引
Redis connection error err auth < password > called without any password configured for the default user
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
On BFC (block formatting context)
对js中argumens的简单理解
js之预解析
反思|开启B站少女心模式,探究APP换肤机制的设计与实现
SAP TRANSLATE使用数据对象掩码示例
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
随机推荐
SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
[Ted series] how does a habit change my life
js之DOM学习获取元素
5.SQL99标准:内连接和外连接
2. Restricted query
学会使用搜索引擎
[Educational Codeforces Round 80] 解题报告
ogldev-读书笔记
5. Sql99 standard: internal connection and external connection
SAP PI/PO Soap2Proxy 消费外部ws示例
typescript字典的使用
驼峰命名对像
【自我激励系列】你永远不会准备好
2.限定查询
2022.3.14 阿里笔试
1.查看数据库和表
Use of typescript dictionary
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
ABAP 7.4 SQL Window Expression
3. Sort statement