LintCode 翻转链表
来源:互联网 发布:钉钉 阿里云企业邮箱 编辑:程序博客网 时间:2024/05/20 14:27
题目
翻转一个链表样例给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null
题目中默认的节点类
public class ListNode { int val; ListNode next; ListNode(int val) { this.val = val; this.next = null; } }
代码
public class Solution { /** * @param head: The head of linked list. * @return: The new head of reversed linked list. */ public ListNode reverse(ListNode head) { // write your code here if(head == null) return head; ListNode pre = null; ListNode cur = null; ListNode next = null; cur = head; while(cur!=null){ next = cur.next; cur.next = pre; pre = cur; cur = next; } head = pre; return head; }}
参考:
http://blog.csdn.net/xia744510124/article/details/50038461
阅读全文
0 0
- LintCode-翻转链表
- lintcode 翻转链表
- LintCode:翻转链表
- lintcode,翻转链表
- 翻转链表,lintcode
- Lintcode 翻转链表
- LintCode 翻转链表
- 翻转链表-LintCode
- LintCode : 翻转链表
- [Lintcode]翻转链表
- lintcode--翻转链表
- Lintcode翻转链表
- LintCode 翻转链表
- lintcode翻转链表
- LintCode 翻转链表
- Lintcode:翻转链表
- LintCode:翻转链表 II
- 【LintCode】翻转链表 II
- c++知识总结(4)
- Js_Dom(5)__Dom基础<事件event>
- 双亲委派模型和自定义类加载器
- 网络请求图片和json解析,在listView中展示出来
- HDU 6085 Rikka with Candies (暴力压位)
- LintCode 翻转链表
- ssh+jbpm整合
- 在eclipse搭建maven项目
- PHP使用PDO抽象层获取查询结果
- 生成awr报告和手动生成awr快照
- 带边框的背景色
- TensorFlow学习笔记----TF生成数据的方法
- 叽叽歪歪
- jquery中attr和prop的区别