LeetCode:206. Reverse Linked List 发表于 2019-06-23 | 分类于 LeetCode 题目描述 Reverse a singly linked list. Example: 12Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL 用一个虚的头节点(如下的start节点)可以简化代码。 代码实现 12345678910111213141516class Solution: def reverseList(self, head: 'ListNode') -> 'ListNode': if head == None: return head start = ListNode(0) start.next = head tmp = head last = start while tmp != None: nextTmp = tmp.next tmp.next = last last = tmp tmp = nextTmp head.next = None return last