直接反转
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
pre=None # 代表刚刚走过的节点
while pHead: #为空跳出,刚刚走过的节点pre就是末节点
next=pHead.next #取出next
pHead.next=pre #将当前节点的next换为上个节点pre
pre=pHead #换完之后当前节点走过,pre更新
pHead=next #当前节点更新
return pre 
京公网安备 11010502036488号