LeetCode#111 Minimum Depth of Binary Tree

Problem Definition:

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

 

Solution:

1 def minDepth( root):
2         if root==None:
3             return 0
4         if root.left==None or root.right==None:
5             return max(self.minDepth(root.left), self.minDepth(root.right))+1
6         return min(self.minDepth(root.left), self.minDepth(root.right))+1

 

你可能感兴趣的:(LeetCode)