#
经实验该题其实并没有头结点,其所谓头结点即是首元结点
# -*- 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
if not pHead: #空链表则返回
return
res = []
while pHead: # 经实验该题其实并没有头结点,其所谓头结点即是首元结点
res.append(pHead)
pHead = pHead.next
for i in range(len(res)):
if i == 0: # 第一个比较特殊
res[i].next = None
else:
res[i].next = res[i - 1] # 后一个指向前一个
pHead = res[-1]
return pHead