【LEETCODE】111-Minimum Depth of Binary Tree
来源:互联网 发布:淘宝网天猫旗舰店 编辑:程序博客网 时间:2024/05/13 23:47
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.
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def minDepth(self, root): """ :type root: TreeNode :rtype: int """ if root == None: #root为空,返回0 return 0 elif root.left != None and root.right == None: #只有左子树时,不用考虑右子树的深度,否则会返回1,但是无意义的 return self.minDepth(root.left)+1 elif root.left == None and root.right != None: #同理,只有右子树时 return self.minDepth(root.right)+1 else: return min(self.minDepth(root.left),self.minDepth(root.right))+1 #左右子树都有时,返回最小的深度
0 0
- LeetCode(111)Minimum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree [111]
- LeetCode 111 Minimum Depth of Binary Tree
- [leetcode 111] Minimum Depth of Binary Tree
- [LeetCode 111]Minimum Depth of Binary Tree
- leetCode #111 Minimum Depth of Binary Tree
- leetcode-111 Minimum Depth of Binary Tree
- leetcode 111 Minimum Depth of Binary Tree
- leetcode || 111、Minimum Depth of Binary Tree
- Leetcode[111]-Minimum Depth of Binary Tree
- leetcode[111]:Minimum Depth of Binary Tree
- LeetCode 111 Minimum Depth of Binary Tree
- [leetcode 111] Minimum Depth of Binary Tree
- leetcode-111-Minimum Depth of Binary Tree
- Leetcode #111 Minimum Depth of Binary Tree
- leetcode 111: Minimum Depth of Binary Tree
- LeetCode 111: Minimum Depth of Binary Tree
- 【LEETCODE】111-Minimum Depth of Binary Tree
- CDOJ 1215--Secrete Master Plan【水题】
- 移植UBI的5号错误————UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 0:512, written 0 byte
- 命名空间namespace
- Please,take away my bad luck
- hibernate注解方式来处理映射关系
- 【LEETCODE】111-Minimum Depth of Binary Tree
- UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView
- 隐写术总结
- 未来计算机及外设畅想
- 半自动抓取知乎用户的微博地址(python)(2)
- 迷宫 nyoj 499
- 电阻电容电感二极管三极管在电路中的作用
- IOS--UIScrollView和UIPageControl配合使用
- 【UML视频总结】——RUP