从尾到头打印链表
题目描述
输入为链表的表头输出为需要打印的“新链表”的表头Python 版本提交
class Solution:
# 返回从尾部到头部的列表值序列,例如[1,2,3]
def printListFromTailToHead(self, listNode):
# write code here
res = list()
if listNode:
res.insert(0, listNode.val) # 注意插入的是数值而不是整个对象
while listNode.next:
res.insert(0, listNode.next.val)
listNode = listNode.next
return resC/C++ 版本提交
Last updated