Skip to main content

🟢 剑指 Offer 06. 从尾到头打印链表

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1.py#

# Definition for singly-linked list.# class ListNode:#     def __init__(self, x):#         self.val = x#         self.next = None
class Solution:    def reversePrint(self, head: ListNode) -> List[int]:        res = []        while head:            res.insert(0, head.val)            head = head.next        return res