思路:
先将当前节点数对应的下一个节点数保存下来tmp=pHead.next,然后将上个节点数last赋值给pHead.next(初始last为None)。当前节点pHead赋值给last(成为上一个节点),最后将下一个节点tmp赋值给pHead(成为当前结点)。
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
last=None
while pHead!=None:
tmp=pHead.next
pHead.next=last
last=pHead
pHead=tmp
return last
对于链表什么还是摸不清头脑