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. 享元模式(Flyweight、FlyweightFactory)(围棋棋子共享)

    (使用共享对象可有效地支持大量的细粒度的对象.) 假设开发一个围棋程序,围棋程序的围棋的棋子包含了颜色.大小.位置等信息.在定义一个棋盘容器来存放这些棋子. 我们可以发现,棋盘的成员变量包含了一个棋子 ...

  2. non-identifying and identifying

    An identifying relationship means that the child table cannot be uniquely identified without the par ...

  3. leyou_01_环境搭建

    1.乐优商城项目搭建 前端技术: 基础的HTML.CSS.JavaScript(基于ES6标准) JQuery Vue.js 2.0以及基于Vue的框架:Vuetify 前端构建工具:WebPack ...

  4. Windows Sublime text3 搭建Go语言环境

    第一步:Go环境和配置 1.安装 Go 开发环境(省略),假设Go安装目录为 C:\Go 2.配置环境变量,下面两个环境变脸没有就加上. 资料参考:http://studygolang.com/art ...

  5. H5C3--过渡transition

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. js &&操作符解析

    转载自:http://www.cnblogs.com/huchaoheng/p/4066473.html 前几天看到一个函数,百思不得其解,今天早上醒来看了本js的书,正好讲到操作符的用法,给大家分享 ...

  7. Hackerrank--Mixing proteins(Math)

    题目链接 Some scientists are working on protein recombination, and during their research, they have foun ...

  8. ajax实例解析

    function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint&quo ...

  9. 2019.10.21 csp-s模拟测试81 反思总结

    T1: 把每一行状压,按行DP.设fi,j,k,i表示第几行,j是当前行的1覆盖状态,k是当前行选择按钮的状态.转移的时候枚举j和k,再枚举下一层的按钮选择情况l.如果l和j可以全覆盖当前层则转移合法 ...

  10. mvp例子与MVVM例子

    VMP例子 <!-- 从百度CDN上面找个jquery的链接 --> <!DOCTYPE html> <html lang="en"> < ...