111.二叉树的最小深度
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def minDepth(self, root: TreeNode) -> int: if root is None: return 0 if root.left and root.right: return min(self.minDepth(root.left), self.minDepth(root.right)) + 1 # 3 # / \ # 9 # 返回的应该是2,而不是1 else: return max(self.minDepth(root.left), self.minDepth(root.right)) + 1