首页 > 其他 > 详细

Leetcode 206 Reverse Linked List

时间:2015-06-17 19:45:56      阅读:183      评论:0      收藏:0      [点我收藏+]

Reverse链表。使用三个指针head,a,b,最后head会指向最后一个node,故直接返回head。

x -> x -> x -> x =>  x <- x   x -> x   =>   x <- x x -> x  =>      x <- x <- x  x

h     a      b          a.next = head            h  a     b      a.next = head

def reverse(head)
  return if not head 
    a = head.next
    head.next = nil
  while a
    b = a.next
    a.next = head
    head = a
    a = b
  end
  head
end

 

Leetcode 206 Reverse Linked List

原文:http://www.cnblogs.com/lilixu/p/4584022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!