题目链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
难度:简单
描述:
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。
题解
class Solution:
def reversePrint(self, head: ListNode) -> List[int]:
ret = []
while head is not None:
ret.append(head.val)
head = head.next
return ret[::-1]
# 其他语言可以用栈保存,最后push出来,这里我偷懒了