题目描述
输入一个链表,反转链表后,输出新链表的表头。
Python
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
if pHead is None:
return None
pre = None
while pHead.next:
tmp = pHead.next
pHead.next = pre
pre = pHead
pHead = tmp
pHead.next = pre
return pHead
网友评论