JZ53 数字在升序数组中出现的次数从尾到头打印链表

83 阅读1分钟

[](题解 | #从尾到头打印链表#_牛客博客 (nowcoder.net))

class Solution:
    # 返回从尾部到头部的列表值序列,例如[1,2,3]
    def printListFromTailToHead(self, listNode):
        # write code here
        if not listNode:
            return []
        re = []
        while listNode:
            re.append(listNode.val)
            listNode = listNode.next
        return re[::-1]
s = Solution()

l = ListNode(1)
l.next = ListNode(2)
l.next.next = ListNode(3)
print(s.printListFromTailToHead(l))