Login light

leetcode/104. 二叉树的最大深度.md

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def maxDepth(self, root: TreeNode) -> int:
        if None == root:
            return 0
        if root.left == None and root.right == None:
            return 1
        return self.maxDepthx(1, root)
    def maxDepthx(self, length, child: TreeNode):
        if None == child:
            return length
        if None == child.left and None == child.right:
            return length
        return max(self.maxDepthx(length + 1, child.left), self.maxDepthx(length + 1, child.right))