Leetcode no. 111
来源:互联网 发布:jsp添加java代码 编辑:程序博客网 时间:2024/05/20 09:06
111. Minimum Depth of Binary Tree
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. * 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; return helper(root, 0); } private int helper(TreeNode root, int depth){ if (root.left== null && root.right== null) return depth+1; int left=Integer.MAX_VALUE, right=Integer.MAX_VALUE; if (root.left!= null) left= helper(root.left, depth+1); if (root.right!= null) right= helper(root.right, depth+1); return Math.min(left, right); }}
0 0
- Leetcode no. 111
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Leetcode no. 228
- Leetcode no. 313
- Android中ListView的使用(三)----- 提升ListView运行效率
- JVM: How to analyze Thread Dump
- 十八. 增加一个项目协作留言板功能(四)----- 增加实施步骤的增删改查功能
- 使用cocoaPods import导入时没有提示的解决办法
- HQL:使用面向对象的HQL查询语言
- Leetcode no. 111
- web笔记
- 操作系统-锁机制
- jQuery遍历
- cygwin安装Cygwin/X需要选择的包
- SecureCRT简单的安装和激活教程
- DbUtil组件
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- Android输入事件从读取到分发二:谁在循环监听事件的到来