Minimum Depth of Binary Tree Java
来源:互联网 发布:linux 退出python命令 编辑:程序博客网 时间:2024/06/06 00:58
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; } if (root.left == null && root.right == null) { return 1; } int minLeft=minDepth(root.left); int minRight=minDepth(root.right); if(minLeft == 0) {minLeft = Integer.MAX_VALUE; } if(minRight == 0){minRight = Integer.MAX_VALUE;} return Math.min(minLeft,minRight)+1; }}
0 0
- [Leetcode] Minimum Depth of Binary Tree (Java)
- Minimum Depth of Binary Tree Java
- Minimum Depth of Binary Tree (Java)
- Minimum Depth of Binary Tree Java
- [LeetCode][Java] Minimum Depth of Binary Tree
- LeetCode|Minimum Depth of Binary Tree-java
- (java)Minimum Depth of Binary Tree
- leetcode:Minimum Depth of Binary Tree 【Java】
- minimum-depth-of-binary-tree java code
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- 获取六边形头像(封装六边形方法)
- 用 Maven 做项目构建
- 【点、大小、矩形、范围】
- Fedora 22学习(2)
- JavaSE实战——API(中) 集合框架
- Minimum Depth of Binary Tree Java
- IOS常用的第三方库和使用方法
- MySQL MyISAM和InNodb备份与恢复技巧
- GRE写作必备句型
- 进程间和线程间通信
- C++知识点随笔(五):虚继承
- 分析java对象内存占用
- js 页面智能判断浏览器版本
- linux系统工程师面试题(附答案)