思路
構建一個列表,每次在頭插入
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回從尾部到頭部的列表值序列,例如[1,2,3]
def printListFromTailToHead(self, listNode):
# write code here
result = []
p = listNode
while p :
result.insert(0,p.val)
p = p.next
return result