【剑指】从尾到头打印链表
作者:互联网
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def reversePrint(self, head: ListNode) -> List[int]:
p = head
ans = []
while p:
ans.append(p.val)
p = p.next
return ans[::-1]
标签:__,head,val,到头,self,next,链表,从尾,ans 来源: https://www.cnblogs.com/wangshujaun/p/14220494.html