LeetCode 111 Minimum Depth of Binary Tree
2015-11-27 10:35
246 查看
题目描述
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.
分析
参考:LeetCode 104 Maximum Depth of Binary TreeMinimum Depth的定义如下:
代码
[code] public static int minDepth(TreeNode root) { if (root == null) { return 0; } if (root.left == null && root.right == null) { return 1; } else if (root.left != null && root.right == null) { return minDepth(root.left) + 1; } else if (root.left == null && root.right != null) { return minDepth(root.right) + 1; } return Math.min(minDepth(root.left), minDepth(root.right)) + 1; }
相关文章推荐
- 安卓自带的屏幕录制命令
- 对抗明文口令泄露 —— Web 前端慢 Hash
- EntityFunctions
- java date和时间戳转化
- 关于flex的crossdomain.xml文件存放目录
- ecshop 订单-》设置默认收货地址,或者删除
- Linux系统启动过程分析
- python如何得到13位时间戳?
- winform Treeview Checkbox选择事件
- ARM汇编指令
- C++贪吃蛇——(2)
- org.springframework.context.ApplicationContextAware
- SQL2000/2005&2008中master数据库备份与恢复
- 浅谈C#垃圾回收
- php时间设置为本地
- 用matlab绘制幂函数
- GridView实现多表头合并,解决表头数据对不齐
- Intellij IDEA 14的注册机(Java版)
- 【转】谁说Vim不是IDE?(二)
- java Io梳理