当前位置:网站首页>反转链表练习
反转链表练习
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
边栏推荐
- redis连接出错 ERR AUTH <password> called without any password configured for the default user.
- Educational Codeforces Round 81 (Rated for Div. 2)
- 设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
- CSDN很火的汤小洋老师全部课程总共有哪些(问号问号问号)
- 二叉树的深度
- js之什么是事件?事件三要素以及操作元素
- Preliminary configuration of OpenGL super Dictionary (freeglut, glew, gltools, GLUT)
- [COCI] Vještica (子集dp)
- ABAP 实现发布RESTful服务供外部调用示例
- MySQL index
猜你喜欢
随机推荐
[CF 1425D]Danger of Mad Snakes(组合计数+容斥)
每日一题 | 曾被反转链表支配的恐惧
MySQL isolation level
积性函数与迪利克雷卷积
1. View databases and tables
keytool: command not found
[LNOI2014]LCA——树链剖分——多点LCA深度和问题
技能点挖坑
redis连接出错 ERR AUTH <password> called without any password configured for the default user.
经典套路:一类字符串计数的DP问题
10.更新操作
Django使用mysql数据库报错解决
数组扁平化
[self motivation series] you'll never be ready
莫比乌斯反演
Thorough inquiry -- understanding and analysis of cocos2d source code
[牛客练习赛68]牛牛的粉丝(矩阵快速幂之循环矩阵优化)
[hdu6833]A Very Easy Math Problem(莫比乌斯反演)
11. Table and library management
Design optimization of MySQL database








