方法1:用递归的方法

方法2:用队列实现层序遍历,求层序遍历返回数组的值即可

class Solution:
    def maxDepth(self , root: TreeNode) -> int:
        # write code here
        left_max = 0
        right_max = 0
        if not root:
            return 0
        left_max = 1 + self.maxDepth(root.left)
        right_max = 1 + self.maxDepth(root.right)    
        return max(left_max, right_max)