码迷,mamicode.com
首页 >  
搜索关键字:treedepth    ( 10个结果
剑指offer——60二叉树的深度
题目描述 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 题解: 简单的深度遍历即可。 1 class Solution { 2 public: 3 int TreeDepth(TreeNode* pRoot) 4 { 5 i ...
分类:其他好文   时间:2019-10-20 13:12:04    阅读次数:89
面试39---二叉树的深度
题目链接 求解二叉树的深度,延伸可见leetcode110题。 法一:dfs。 1 private int TreeDepth(TreeNode root) { 2 if(root == null) { 3 return 0; 4 } 5 int l = TreeDepth(root.left); ...
分类:其他好文   时间:2018-05-09 14:56:24    阅读次数:127
剑指offer三十八之二叉树的深度
一、题目 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 二、思路 递归,详见代码。 三、代码 public class Solution { public int TreeDepth(TreeNode pRoot) { if ...
分类:其他好文   时间:2017-10-12 16:13:23    阅读次数:155
深度优先算法--对DFS的一些小小的总结(一)
提到DFS,我们首先想到的是对树的DFS,例如下面的例子:求二叉树的深度 int TreeDepth(BinaryTreeNode* root){ if(root==nullptr)return 0; int left=TreeDepth(root->left); int right=TreeDep ...
分类:编程语言   时间:2017-09-14 23:39:48    阅读次数:206
二叉树的深度
输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 思路:使用递归的方法分别计算左右子树的深度 public class Solution { public int TreeDepth(TreeNode pRoot){ retur ...
分类:其他好文   时间:2017-03-01 23:28:31    阅读次数:301
剑指offer(四十五)之二叉树的深度
题目描述 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 代码: public class Solution { public int TreeDepth(TreeNode pRoot){ if(pRoot==null) return 0; retur...
分类:其他好文   时间:2016-06-12 02:31:25    阅读次数:127
二叉树的深度
int TreeDepth(BinaryTreeNode* pRoot) { if (pRoot == NULL) return 0; int nLeft = TreeDepth(pRoot->m_pLeft); int nRight = TreeDepth(pRoot->m_pRight); return (nLeft > nRight) ? (nLeft + 1) : (nRigh...
分类:其他好文   时间:2015-07-10 22:22:09    阅读次数:156
[Leetcode]-Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Hide Tags :Tree ,De...
分类:其他好文   时间:2015-07-06 12:25:10    阅读次数:114
C++算法之 判断是否为平衡二叉树 求二叉树的镜像
1:判断是否为平衡二叉树: //方法1: int TreeDepth(BTree* pRoot) { if (pRoot == NULL) return 0; int nLeftDepth = TreeDepth(pRoot->m_pLeft); int nRightDepth = TreeDepth(pRoot->m_pRight); return (nLeftD...
分类:编程语言   时间:2015-01-07 18:49:54    阅读次数:202
函数递归的几个例子
1.求二叉树的深度int TreeDepth(binary_Tree* pRoot){ if(pRoot==NULL) return 0; int nLeft=TreeDepth(pRoot->left); int nRight=TreeDepth(pRoot->ri...
分类:其他好文   时间:2014-08-31 17:06:01    阅读次数:132
10条  
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!