leetcode:Minimum Depth of Binary Tree【Python版】
2014-10-19 10:01
375 查看
1、类中递归调用添加self;
2、root为None,返回0
3、root不为None,root左右孩子为None,返回1
4、返回l和r最小深度,l和r初始为极大值;
2、root为None,返回0
3、root不为None,root左右孩子为None,返回1
4、返回l和r最小深度,l和r初始为极大值;
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param root, a tree node # @return an integer def minDepth(self, root): if root == None: return 0 if root.left==None and root.right==None: return 1 l,r = 9999,9999 if root.left!=None: l = self.minDepth(root.left) if root.right!=None: r = self.minDepth(root.right) if l<r: return 1+l return 1+r
相关文章推荐
- [leetcode]Minimum Depth of Binary Tree @ Python
- Leetcode_minimum-depth-of-binary-tree (c++ and python version)
- 【Leetcode】【python】Minimum Depth of Binary Tree
- leetcode Minimum Depth of Binary Tree python
- 【LeetCode with Python】 Minimum Depth of Binary Tree
- [LeetCode]题解(python):111-Minimum Depth of Binary Tree
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
- [Leetcode] Minimum Depth of Binary Tree
- [面试真题] LeetCode:Minimum Depth of Binary Tree
- leetcode--Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - DFS
- LeetCode:Minimum Depth of Binary Tree
- 【leetcode】Minimum Depth of Binary Tree
- leetcode -- Minimum Depth of Binary Tree
- LeetCode_Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- 【LeetCode with Python】 Maximum Depth of Binary Tree
- LeetCode题目笔记(一) -- Minimum Depth Of Binary Tree
- [leetcode刷题系列]Minimum Depth of Binary Tree