码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]206. Reverse Linked List

时间:2017-05-06 10:22:05      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:span   problems   ble   sub   next   ref   bsp   tno   ever   

Reverse a singly linked list.

click to show more hints.

 

Subscribe to see which companies asked this question.

 1 public ListNode reverseList(ListNode head) {
 2             if(head==null) return null;
 3             if(head.next==null) return head;
 4             ListNode pre = head;
 5             ListNode cur = head.next;
 6             pre.next = null;
 7             ListNode next;
 8             while(cur != null){
 9                 next = cur.next;
10                 cur.next = pre;
11                 pre = cur;
12                 cur = next;
13             }
14             return pre;
15         }

 

[LeetCode]206. Reverse Linked List

标签:span   problems   ble   sub   next   ref   bsp   tno   ever   

原文地址:http://www.cnblogs.com/zle1992/p/6815467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!