首页 > 其他 > 详细

leetcode——543. 二叉树的直径

时间:2019-11-23 00:25:30      阅读:125      评论:0      收藏:0      [点我收藏+]

似懂非懂。。

class Solution:
    def diameterOfBinaryTree(self, root: TreeNode) -> int:
        self.ans=1
        def depth(node):
            if not node:
                return 0
            L=depth(node.left)
            R=depth(node.right)
            self.ans=max(self.ans,L+R+1)
            return max(L,R)+1
        depth(root)
        return self.ans-1
执行用时 :52 ms, 在所有 python3 提交中击败了95.04%的用户
内存消耗 :16.5 MB, 在所有 python3 提交中击败了5.10%的用户
 
——2019.11.22

leetcode——543. 二叉树的直径

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

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