LeetCode 111 Minimum Depth of Binary Tree
2016-04-07 00:52
260 查看
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.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
public int minDepth(TreeNode root) { if (root == null) return 0; int rightDepth = minDepth(root.right); int leftDepth = minDepth(root.left); if (rightDepth != 0 && leftDepth != 0) return Math.min(leftDepth, rightDepth) + 1; return rightDepth != 0 ? rightDepth + 1 : leftDepth + 1; }
相关文章推荐
- 树的子结构
- checkbox与<c:forEach>在开发中遇到的问题记录
- 禁止WebBrowser网页跳转时发出的声音
- 《希腊城邦制度》 ——读希腊史笔记 顾准
- 从统计看机器学习(一) 一元线性回归
- AOP概念与动态代理
- 垃圾收集器要点
- 刷机前对LG Nexus 5进行双清的方法(图文讲解)
- 解决U盘挂载到linux上没有写和执行的权限
- 《深入理解计算机系统》读书笔记第七章——链接
- 练习14:提示和传递
- MySQL中alter用法
- 风雨扬州路
- No matching provisioning profiles found: None of the valid provisioning profiles include the device
- C++第3次作业
- centos6下安装git
- 后台登陆地址
- 实现人机下三字棋
- OC阅读笔记十四:dealloc
- Sql Server 三种分页方式及测试