# 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
相关文章
- 02-14Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
- 02-14LeetCode Binary Tree Preorder Traversal 先根遍历
- 02-14【LeetCode】297. Serialize and Deserialize Binary Tree 解题报告(Python)
- 02-14【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)
- 02-14LeetCode不定时刷题——Convert Sorted Array to Binary Search Tree
- 02-14LeetCode 199: Binary Tree Right Side View
- 02-14[leetcode-606-Construct String from Binary Tree]
- 02-14[LeetCode] 968. Binary Tree Cameras
- 02-14[LeetCode] 968. Binary Tree Cameras 二叉树相机
- 02-14【Leetcode】700. Search in a Binary Search Tree