leetcode?python Maximum Depth of Binary Tree

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode?python Maximum Depth of Binary Tree相关的知识,希望对你有一定的参考价值。

#-*- coding: UTF-8 -*-
# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def maxDepth(self, root):
        if root==None:return 0
        leftDepth=self.maxDepth(root.left)
        rightDepth=self.maxDepth(root.right)
        
        return leftDepth+1 if leftDepth >rightDepth else (rightDepth+1)

以上是关于leetcode?python Maximum Depth of Binary Tree的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode&Python] Problem 628. Maximum Product of Three Numbers

Leetcode刷题记录[python]——104 Maximum Depth of Binary Tree

[LeetCode&Python] Problem 559. Maximum Depth of N-ary Tree

[LeetCode in Python] 5393 (M) maximum points you can obtain from cards 可获得的最大点数

[leetcode-646-Maximum Length of Pair Chain]

[Leetcode] 1343. Maximum Product of Splitted Binary Tree | 分裂二叉树的最大乘积