"""
反转一个单链表。
示例:
输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
"""
def reverseList(head):
if head is None:
return None
prev = None
tmp = head
while head:
head = head.next
if head is None:
break
tmp.next = prev
prev = tmp
tmp = head
tmp.next = prev
return tmp
206_反转链表
最新推荐文章于 2024-08-13 21:21:03 发布