leetcode Minimum Depth of Binary Tree 1.11 难度系数1
来源:互联网 发布:python 爬虫工作原理 编辑:程序博客网 时间:2024/05/21 10:39
Question:
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 binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int minDepth(TreeNode root) { if(root==null) return 0; int l = minDepth(root.left); int r = minDepth(root.right); if(l==0) return r+1; if(r==0) return l+1; return Math.min(l, r) + 1; } }
0 0
- leetcode Minimum Depth of Binary Tree 1.11 难度系数1
- leetcode Maximum Depth of Binary Tree 1.9 难度系数1
- leetcode-1-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 - BFS
- [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
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- 1
- Hadoop常见的45个问题
- Maven仓库汇总
- Spring@Autowired注解与自动装配
- [Linux]ln -s对目录建立符号连接后报错“符号连接层数过多”的解决办法
- leetcode Minimum Depth of Binary Tree 1.11 难度系数1
- 插入排序算法
- 英特尔大败局
- 三大措施设置数据库安全 保障网站安全运营
- From LinkedIn
- [转]背包问题九讲
- 专家讲解数据库安全 防范黑客入侵技术综述
- 中美印日四国程序员比较
- 如何修改Linux系统下的PATH(如何添加自己的路径到PATH)