输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
1 # -*- coding:utf-8 -*- 2 # class ListNode: 3 # def __init__(self, x): 4 # self.val = x 5 # self.next = None 6 7 class Solution: 8 # 返回从尾部到头部的列表值序列,例如[1,2,3] 9 def __init__(self): 10 self.result = [] 11 12 def track(self,listNode): 13 if listNode.next: 14 self.track(listNode.next) 15 self.result.append(listNode.val) 16 17 def printListFromTailToHead(self, listNode): 18 if listNode: 19 self.track(listNode) 20 return self.result 21 # write code here