111. Minimum Depth of Binary Tree
来源:互联网 发布:激光内雕机软件 编辑:程序博客网 时间:2024/06/07 04:06
原文题目:
111. Minimum Depth of Binary Tree
读题:
求最小深度,这和求树的最大深度差不多,只不过需要注意当左子树或者右子树为空时,最小深度并不为0,而是取决于非空子树的最小深度
# 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 not root: return 0 lengthL = self.minDepth(root.left) lengthR = self.minDepth(root.right) if not lengthL: return lengthR + 1 if not lengthR: return lengthL + 1 return min(lengthR,lengthL) + 1
阅读全文
0 0
- 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
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 239. Sliding Window Maximum 滑动窗口最大值
- mysql导出数据乱码
- PHP cURL中CURLOPT_CONNECTTIMEOUT和CURLOPT_TIMEOUT的区别
- Test5
- 初识Android Studio
- 111. Minimum Depth of Binary Tree
- 解决WinDbg调试VMWare虚拟机连接不上
- Oracle 表空间查询、添加
- UML表示以及对应的实现代码
- C 语言的static 与head File
- turtlebot的mobile_base节点
- 阿里云媒体转码MTS使用教程
- 手机app测试之常用测试手段
- 第三方:微信---如何使用第三方微信登录