题目
给你单链表的头节点 head,请你反转链表,并返回反转后的链表。
输出:head = [1,2,3,4,5]
输入:[5,4,3,2,1]
题解
考查链表构造的了解,递归办法的实现
def reverseList(head):
if not head or not head.next:
return head
curHead = reverseList(head.next)
head.next.next = head
head.next = None
return curHead