剑指offer
从尾到头打印链表
输入一个链表,按链表值从尾到头的顺序返回一个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 printListFromTailToHead(self, listNode): 10 # write code here 11 result = [] 12 head = listNode 13 while head is not None: 14 result.append(head.val) 15 head = head.next 16 result.reverse() # 反向列表 17 return result