image.png
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
# 递归方法
if head == None or head.next == None:
return head
ret = self.reverseList(head.next)
head.next.next = head
head.next = None
return ret