LeetCode---111. Minimum Depth of Binary Tree

题目:

给出一个二叉树,发现它的最小深度。最小深度指的是从根节点到最近的叶节点的路径的长度。

Python题解
class Solution(object):
    def minDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if root is None:
            return 0
        if root.left is None:
            return self.minDepth(root.right) + 1
        if root.right is None:
            return self.minDepth(root.left) + 1
        left_depth = self.minDepth(root.left)
        right_depth = self.minDepth(root.right)
        return min(left_depth, right_depth) + 1

你可能感兴趣的:(leetcode,111.,Minimum,Depth,of,Binary,T,leetcode,二叉树)