面试之路(28)-反转链表(reverse ListNode)
2016-05-09 21:22
549 查看
反转链表:
java类
public class ListNode{ int key; ListNode next; }
思路分析:
需要三个指针,current,prev和next。current.next = prev之前需要next = current.next(判断next是否为空),同时一直往后遍历
while(node != null)
-
代码:
public ListNode reverseList(ListNode head){ ListNode prev = null; ListNode node = null; ListNode current = head; while(current != null){ ListNode next = current.next; if(next == null){ node = current; } current.next = prev; prev = current; current = next; } return node; }
相关文章推荐
- 面试之路(28)-反转链表(reverse ListNode)
- node crypto sha192 翻译为java
- 去掉 sudo 安装和运行 node 模块的方法
- NodeJS学习笔记之FS文件模块
- node.js 操作excel
- 用NODEJS处理EXCEL文件导入导出
- 如何使用Node.js在Ubuntu上写一个HelloWorld程序
- nodejs开发利器
- Ubuntu上如何安装Node.js
- node.js setup wizard ended prematurely Win7安装nodejs失败解决方法
- NodeJS、NPM安装配置步骤(windows版本)
- 13 fabulous frameworks for Node.js
- Leetcode 19. Remove Nth Node From End of List
- 《Nodejs开发加密货币》之十一:一张图熟练使用Async组件解决回调大坑
- nodeJS简介及应用场景
- LeetCode OJ 222. Count Complete Tree Nodes
- hadoop2集群中的datanode启动以后自动关闭的问题
- LeetCode 117. Populating Next Right Pointers in Each Node II
- LeetCode 116. Populating Next Right Pointers in Each Node
- Ambari node heartbeat lost