代码的鲁棒性:反转链表
2016-08-27 19:55
211 查看
输入一个链表,反转链表后,输出链表的所有元素。
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode ReverseList(ListNode head) { if(head==null) return null; if(head.next==null){ return head; } ListNode pre=null; ListNode next=null; while(head!=null){ next=head.next; head.next=pre; pre=head; head=next; } return pre; } }
相关文章推荐
- 我对javaFx的简单认识
- Spring IOC容器中注入bean
- java多线程相关内容
- 曾经做过的c练习(1-5)
- LUA单继承与多继承实验
- AOP( aspect-oriented programming)面向切面编程
- Java并发编程:volatile关键字解析
- C Peimer 第10章编程习题
- SpringMVC的controller多线程的问题
- 常用的webservice客户端和spring集成的方法
- c++ 指针
- Java对象转Json字符串
- LeetCode 1. Two Sum
- PhpStorm日志报错:Failed to change timestamp of the file 'your.php'
- MAC系统指定JDK版本的方法
- c++ string类的使用方法
- MySQL - MySQL++在c++11环境下接口设计
- tslib ts_test显示界面,但触摸无反应,运行qt4命令触摸有反应
- POJ 1042 -Gone Fishing
- 代码的鲁棒性:链表中倒数第k个结点