题目链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
难度:简单

描述:
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。

题解

  1. class Solution:
  2. def reversePrint(self, head: ListNode) -> List[int]:
  3. ret = []
  4. while head is not None:
  5. ret.append(head.val)
  6. head = head.next
  7. return ret[::-1]
  8. # 其他语言可以用栈保存,最后push出来,这里我偷懒了