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. 从数据库导出数据到excel之List<List<Object>>导出

    说明:有时候数据处理为List<List<Object>>更方便 姊妹篇:从数据库导出数据到excel之List<Map<>>导出 兄弟篇:从数据库导出 ...

  2. Træfɪk 服务发现解决方案

    Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It s ...

  3. 关于浏览器和IIS基础的简单理解

    浏览器 输入域名或者IP地址,按回车访问后:发生了什么??IIS是如何工作的?为什么能这么工作?? 1    浏览器和IIS 分别是两个应用程序:浏览器访问网址实际就是  两个应用程序的数据交互往来: ...

  4. Spark性能优化:资源调优篇(转)

    在开发完Spark作业之后,就该为作业配置合适的资源了.Spark的资源参数,基本都可以在spark-submit命令中作为参数设置.很多Spark初学者,通常不知道该设置哪些必要的参数,以及如何设置 ...

  5. 请求MWS报错401:Access Denied

    跑MWS接口,报错: Caught Exception: Access denied Response Status Code: Error Code: AccessDenied Error Type ...

  6. JAVA-Unit04: SQL(高级查询)

    Unit04: SQL(高级查询) 查看SMITH的上司在那个城市工作? SELECT e.ename,m.ename,d.loc FROM emp e,emp m,dept d WHERE e.mg ...

  7. AT指令(二)

    1.常用操作1.1 AT命令解释:检测 Module 与串口是否连通,能否接收 AT 命令:命令格式:AT<CR>命令返回:OK (与串口通信正常)             (无返回,与串 ...

  8. CSV 参数化

    配置CSV Data Set Config 图 3 配置CSV Data Set Config Filename:                        指保存信息的文件目录,可以相对或者绝对 ...

  9. PDA后台运行、安装程序

    ////启动最新版本安装(后台安装模式),结束更新程序            //string cabPath = @"\Application Data\QY.DDM.PDA.CAB&qu ...

  10. Linux基础综合练习

    Linux基本操作综合练习 1.建立用户zhangsan,密码使用明文123456: 命令:useradd -p 123456 zhangsan 解释: 参数 -p 添加明文密码 useradd添加用 ...