輸入一個鏈表,按鏈表值從尾到頭的順序返回一個ArrayList。app
# -*- coding:utf-8 -*- class Solution: # 返回從尾部到頭部的列表值序列,例如[1,2,3] def printListFromTailToHead(self, listNode): # write code here l = [] while listNode: l.append(listNode.val) listNode = listNode.next l = l[::-1] return l