题目:输入一个链表,从尾到头打印链表每个节点的值。
思路:append函数移动,reserve函数调序
code:123456789101112131415161718# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # 返回从尾部到头部的列表值序列,例如[1,2,3] def printListFromTailToHead(self, listNode): # write code here Arr=[] Head=listNode while head: Arr.append(head.val) head=head.next Arr.reverse() return Arr