1 Star 0 Fork 0

ZENGWatermelon/LeetCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
剑指 Offer 06. 从尾到头打印链表.py 991 Bytes
一键复制 编辑 原始数据 按行查看 历史
sunzhaoc 提交于 2020-12-03 20:23 . master
'''
Description:
Version: 1.0
Author: Vicro
Date: 2020-12-03 20:11:05
LastEditTime: 2020-12-03 20:22:47
FilePath: \Leetcode\剑指 Offer 06. 从尾到头打印链表.py
'''
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
"""
RESULT: Accept
TIME: 56ms BEAT 37.52%
MEMORY: 15MB BEAT 43.29%
Description:
"""
# class Solution:
# def reversePrint(self, head: ListNode) -> List[int]:
# res = []
# while head:
# res.append(head.val)
# head = head.next
# return res[::-1]
"""
RESULT: Accept
TIME: 40ms BEAT 92.69%
MEMORY: 25.5MB BEAT 5.04%
Description: 递归方法
"""
class Solution:
def reversePrint(self, head: ListNode) -> List[int]:
def function(node):
if not node: return
res.append(node.val)
function(node.next)
res = []
function(head)
return res[::-1]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/watermelonTT/LeetCode.git
git@gitee.com:watermelonTT/LeetCode.git
watermelonTT
LeetCode
LeetCode
master

搜索帮助