Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Hide Tags

Tree Depth-first Search

/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode *root) {
if(root==NULL)
return ;
int i=maxDepth(root->left)+;
int j=maxDepth(root->right)+;
return max(i,j);
}
};

Maximum Depth of Binary Tree 树的最大深度的更多相关文章

  1. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  2. [LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  3. [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  4. [Leetcode] Maximum depth of binary tree二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  6. [LeetCode] 104. Maximum Depth of Binary Tree ☆(二叉树的最大深度)

    描述 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l ...

  7. LeetCode OJ:Maximum Depth of Binary Tree(二叉树最大深度)

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  8. leetCode 104.Maximum Depth of Binary Tree(二叉树最大深度) 解题思路和方法

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  9. Maximum Depth of Binary Tree(二叉树最大深度)

    来源:https://leetcode.com/problems/maximum-depth-of-binary-tree Given a binary tree, find its maximum ...

随机推荐

  1. webServices学习三(概念详解)

    WebService通过HTTP协议完成远程调用: (深入分析) WebService只采用HTTP POST方式传输数据,不使用GET方式; -- 握手,WSDL-get, 普通http post的 ...

  2. Docker(四)安装Redis

    1.安装redis https://blog.csdn.net/qq_29917523/article/details/78019511 2.测试连接

  3. ubuntu 已安装 post-installation 脚本 返回错误状态 1

    1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名 2.$ sudo mkdir /var/lib/dpkg/inf ...

  4. 服务器安装软件时提示Error launching installer

    一台特殊的服务器 安装tomcat失败 经查询 是语言问题 解决办法: 然后重启

  5. invalid use of null value

    给mysql的数据表的一个字段插入数据,不成功, 然后在数据表设计中,把不是null勾选上,又提示 invalid use of null value 这种情况比较尴尬 只能删掉这一个字段,然后新建一 ...

  6. jnhs-Myeclipse 10注册教程unable to access jarfile cracker.jar

    直接双击jar文件就可以 打开后,随便写一个名字 然后复制LICENSE_KEY的内容,打开myeclipse 在Code那里粘贴你刚才复制的内容,然后点击Save & Active Now ...

  7. hashhMap

    # hashMap原理 # HashMap是一个双列集合,是线程不安全的.以key.value的形式储存值.底层是由数组+链表+红黑树组成的,数组是HashMap的主干,链表则是主要为了解决哈希冲突而 ...

  8. sqlserver 2008 R2 安装教程(心得记录)

    在这里简单的记录下自己安装sqlserver的过程吧(本人以前安装失败过,然后卸载了,就一直没用,现在由于工具原因,重新安装,过程相对第一次安装会复杂点) 1.首先,把以前安装的注册表的对应c盘的文件 ...

  9. 关于python的元组操作

    关于元组: 元组和列表是类似的,但是元组中的数据是不可以修改的. 元组是一对 () 元组操作: 元组是不可以修改的所以对元组的操作极少 定义空元组(因为元组一旦创建,数据不可被修改,所以极少创建空元组 ...

  10. java-多线程的练习----妖,等待唤醒,代码重构,lock到condition

    1 需求 资源有姓名和性别. 两个线程,    一个负责给姓名和性别赋值,    一个负责获取姓名和性别的值. 要求1,运行一下,解决程序的 "妖"的问题. 要求2,实现正确数据的 ...