206. Reverse Linked List
2016-03-09 23:26
281 查看
Reverse a singly linked list.
click to show more hints.
Subscribe to see which companies asked this question
click to show more hints.
Subscribe to see which companies asked this question
//递归 public class Solution { public ListNode reverseList(ListNode head) { if(head==null||head.next==null)return head; ListNode tmp =head.next; head.next=null; ListNode rev_list=reverseList(tmp); tmp.next=head; return rev_list; } } //非递归 public class Solution { public ListNode reverseList(ListNode head) { if(head==null||head.next==null)return head; ListNode t1=head; ListNode t2 =head.next; head.next=null; while(t2!=null){ ListNode t3=t2.next; t2.next=t1; t1=t2; t2=t3; } return t1; } }
相关文章推荐
- interview sum
- android的选项菜单
- MFC按钮控件
- 记忆化搜索,FatMouse and Cheese
- UITableView调优
- Transaction类
- Activity的四种启动模式
- finally为什么要在try块中的return之前执行
- 影评之火影忍者博人传
- 二维码生成,中间加入图片
- 虚拟机下添加G++编译c++
- C编译: 动态连接库 (.so文件)
- Android Material Design学习之五CollapsingToolbarLayout
- 004.Java中怎么跳出多重循环?
- 作业1
- Java 的Comparable 和 Comparator
- ViewPage和内部View的事件机制
- 八、优先队列、堆排序
- Linux core文件
- 1044 - Palindrome Partitioning(记忆化DP)