minimum-depth-of-binary-tree
来源:互联网 发布:ant java fork 编辑:程序博客网 时间:2024/05/16 11:28
1、链接: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.
2、思路:递归,以当前根结点为根的最小高度为 1+Min{左子树最小高度,右子树最小高度}
3、代码:
public class Solution { public int run(TreeNode root) { if(root == null) return 0; return minimumDepth(root); } private int minimumDepth(TreeNode root) { if(root.left == null && root.right == null){ return 1; } if(root.left == null) return 1 + minimumDepth(root.right); if(root.right == null) return 1 + minimumDepth(root.left); return 1+Math.min(minimumDepth(root.left), minimumDepth(root.right)); }}
阅读全文
0 0
- 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
- 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
- Linux连接redis客户端出现Could not connect to Redis at 127.0.0.1:6379: Connection refused
- HashSet HashMap Hashtable的区别
- SRS + ffmpeg 推即时视频流
- 人工神经网络
- Visual Studio 2012 控制台应用程序,打开记事本,打开网址的方法 02
- minimum-depth-of-binary-tree
- keras tips&problems
- Feign:web service client(译)
- 使用list和tuple
- bzoj5027 数学题(扩欧)
- point 问题
- MyEclipse的silksvn插件如何清除本地已有的svn账号
- 第3步:打包flaskr
- 大白菜的java开发学习之旅---c3p0和dbcp的配置文件