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

 

posted @ 2015-07-21 20:19  曾可爱  阅读(95)  评论(0编辑  收藏  举报