Leetcode-206题:Reverse Linked Lis
2016-09-26 本文已影响8人
八刀一闪
题目
Reverse a singly linked list.
代码
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head == None:
return None
tail = head
while tail.next != None:
next = tail.next
tail.next = next.next
next.next = head
head = next
return head