[](题解 | #从尾到头打印链表#_牛客博客 (nowcoder.net))
class Solution:
# 返回从尾部到头部的列表值序列,例如[1,2,3]
def printListFromTailToHead(self, listNode):
# write code here
if not listNode:
return []
re = []
while listNode:
re.append(listNode.val)
listNode = listNode.next
return re[::-1]
s = Solution()
l = ListNode(1)
l.next = ListNode(2)
l.next.next = ListNode(3)
print(s.printListFromTailToHead(l))