二叉树的深度
来源:互联网 发布:2016年驾校招生数据 编辑:程序博客网 时间:2024/06/07 12:25
输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。
/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { public int TreeDepth(TreeNode root) { if (root == null) return 0; int leftCount = TreeDepth(root.left)+1; int rightCount = TreeDepth(root.right)+1; int count = Math.max(leftCount, rightCount); return count; }}
阅读全文
0 0
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 二叉树的深度
- 平衡二叉树
- [cnblogs镜像]Unity 烘焙的2种方式
- HDU5952(2016沈阳现场赛)
- [cnblogs镜像]Unity 获取坐标函数 坐标转换函数
- 跨平台ssh客户端Xshell使用指南
- 二叉树的深度
- Python入门记——函数
- [cnblogs镜像]Unity 脚本挂载位置
- 栈的应用
- [cnblogs镜像]Unity脚本生命周期 图解
- 两个链表的第一个公共结点
- [cnblogs镜像]Unity脚本中可以引用的类型
- C结构体的位域
- [cnblogs镜像]Unity局部坐标系与世界坐标系的区别