标签:
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