AcWing 17. 17. 从尾到头打印链表:老实人的笨方法-3针迭代链表翻转
原题链接
简单
作者:
roon2300
,
2020-04-01 00:47:52
,
所有人可见
,
阅读 855
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def printListReversingly(self, head):
"""
:type head: ListNode
:rtype: List[int]
"""
if not head: return []
nhh, nxt = head, head.next
nhh.next = None
while nxt:
p = nxt.next
nxt.next = nhh
nhh = nxt
nxt = p
res = []
p = nhh
while p:
res.append(p.val)
p = p.next
return res