题解 | #二叉树的深度 Python#

二叉树的深度

http://www.nowcoder.com/practice/435fb86331474282a3499955f0a41e8b

  • 用递归思想
class Solution:
    def TreeDepth(self, pRoot):
        # write code here
        if not pRoot:
            return 0
        left = self.TreeDepth(pRoot.left) + 1
        right = self.TreeDepth(pRoot.right) + 1
        return max(left, right)


全部评论

相关推荐

07-17 11:50
门头沟学院 Java
投递腾讯等公司7个岗位
点赞 评论 收藏
分享
Twilight_m...:还是不够贴近现实,中关村那块60平房子200万怎么可能拿的下来,交个首付还差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务