# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def minDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root == None:
return 0
if root.left == None and root.right != None:
return self.minDepth(root.right)+1
if root.left != None and root.right == None:
return self.minDepth(root.left)+1
return min(self.minDepth(root.right),self.minDepth(root.left))+1
相关文章
- LeetCode 110 Balanced Binary Tree(平衡二叉树)(*)
- LeetCode 94:Binary Tree Inorder Traversal(中序遍历)
- LeetCode: Recover Binary Search Tree 解题报告
- [线索二叉树] [LeetCode] 不需要栈或者别的辅助空间,完成二叉树的中序遍历。题:Recover Binary Search Tree,Binary Tree Inorder Traversal
- LeetCode算法题-Second Minimum Node In a Binary Tree(Java实现)
- leetcode先刷_Binary Tree Level Order Traversal II
- 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度
- LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)
- 【LeetCode】94. Binary Tree Inorder Traversal (3 solutions)
- Leetcode:Minimus Depth of Binary Tree