首页 > 其他 > 详细

leetcode——257. 二叉树的所有路径

时间:2019-11-21 20:24:06      阅读:61      评论:0      收藏:0      [点我收藏+]

自己还是没做出来。。

class Solution:
    def binaryTreePaths(self, root: TreeNode) -> List[str]:
        if not root:
            return []
        res=[]
        def helper(root,temp):
            if not root.left and not root.right:
                res.append(temp+[str(root.val)])
            if root.left:
                helper(root.left,temp+[str(root.val)])
            if root.right:
                helper(root.right,temp+[str(root.val)])
        helper(root,[])
        return [->.join(a) for a in res]
执行用时 :48 ms, 在所有 python3 提交中击败了62.38%的用户
内存消耗 :13.8 MB, 在所有 python3 提交中击败了5.68%的用户
 
——2019.11.21

leetcode——257. 二叉树的所有路径

原文:https://www.cnblogs.com/taoyuxin/p/11908046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!