# 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):
if root is None:
return 0
if root.left is None and root.right is None:
return 1
if root.left and root.right is None:
return self.minDepth(root.left) + 1
if root.left is None and root.right:
return self.minDepth(root.right) + 1
if root.left and root.right:
return min(self.minDepth(root.left), self.minDepth(root.right)) + 1
leetcode11 二叉树的最小深度
最新推荐文章于 2022-03-08 15:14:52 发布