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.

class Solution {
public:
int maxDepth(TreeNode *root) {
if(!root) return ;
max_depth = ;
dfs(root,);
return max_depth;
}
void dfs(TreeNode * current, int depth)
{
if(current->left)
{
dfs(current->left, depth+);
}
if (current->right)
{
dfs(current->right,depth+);
}
if(!current->left && !current->right)
{
if(depth > max_depth){
max_depth = depth;
}
}
}
private:
int max_depth;
};

104. Maximum Depth of Binary Tree (Tree; DFS)的更多相关文章

  1. [LeetCode] 104. Maximum Depth of Binary Tree_Easy tag: DFS

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

  2. 104. Maximum Depth of Binary Tree(C++)

    104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...

  3. LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree

    258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...

  4. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  5. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

  6. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

  7. (二叉树 BFS DFS) 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 ...

  8. leetcode 104 Maximum Depth of Binary Tree(DFS)

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

  9. [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 ...

随机推荐

  1. Adreno Profiler 提取手机游戏资源

    https://blog.csdn.net/lly20000/article/details/79774755 step.1 准备工具 1.adb连接工具(我用的cofface adb  ) [cof ...

  2. ecmall 2.3.0 最新补丁20140618

    特别提示:补丁下载地址为:http://download.ecshop.com开头,该地址为ecmall下载站,如果非以http://download.ecshop.com开头,请勿下载,同时请反馈给 ...

  3. Linux 文件名中包含特殊字符

    文件和文件夹的名称中有特殊字符,操作有两种方式( - 在文件名称最前面除外). 例如:文件名为 a&b.c 1.通过转移符 "\" $ touch   a\&b.c ...

  4. 常见企业IT支撑【8、端口回流问题】

    端口回流故障场景,常见于内网启用了Server服务器,使用出口路由设备的外网口NAT映射了一个公网地址,域内内网主机访问了这个公网地址,访问不通. 故障容易出现在办公网内的带有对外Server测试环境 ...

  5. Renesas APIs ***

    一个线程,强行结束另外一个线程,并将其挂起: static void SuspendTask(TX_THREAD *thread) { UINT status = ; UINT state; stat ...

  6. nginx statistics in multi-workers

    1.      从网上下载多进程统计补丁.https://github.com/arut/nginx-patches 2.      Copy补丁文件per-worker-listener到nginx ...

  7. 阿里云专有网络下一键安装RouterOS-ROS系统

    1.阿里云环境centos6.9 x64: 内网网卡为eth0 阿里云的linux下硬盘名称为/dev/vda 注意阿里云的安全组建议开放任意协议和端口,任意IP允许访问 今天测试阿里云2C4G的死活 ...

  8. python的数据类型,数字,布尔,字符串

    1.数字 数字过大,类型会自动变化,这个变化是python2特有的,在python3里都是int,不区分int和long float(浮点型),也就是小数 complex(复数) 2.布尔值 真或者假 ...

  9. [C++]复制构造函数、赋值操作符与隐式类类型转换

    问题:现有类A定义如下: class A{public:        A(int a)                            //构造函数        {              ...

  10. Druid.io系列(七):架构剖析

    1. 前言 Druid 的目标是提供一个能够在大数据集上做实时数据摄入与查询的平台,然而对于大多数系统而言,提供数据的快速摄入与提供快速查询是难以同时实现的两个指标.例如对于普通的RDBMS,如果想要 ...