104. Maximum Depth of Binary Tree (Tree; DFS)
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)的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- 【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 ...
- (二叉树 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 ...
- 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 ...
- [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 ...
随机推荐
- django gunicorn 各worker class简单性能测试
版权归作者所有,任何形式转载请联系作者.作者:petanne(来自豆瓣)来源:https://www.douban.com/note/564871723/ ====================== ...
- ballerina 学习十六 错误&&异常处理
ballerina 的error 处理和elxiir 以及rust 比较类似使用模式匹配,但是他的 error lifting 还是比较方便的 同时check 也挺好,异常处理没什么特殊的 throw ...
- bzoj 4036 按位或 —— min-max容斥+FMT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4036 min-max容斥:https://blog.csdn.net/ez_2016gdgz ...
- C#软件安全 反编译 加密与安全等等
我最近开发了一些C#语言的软件,但是由于这是一种解释型语言,也就是会转化成中间件语言,很容易就被反编译解密,包括exe和dll库等等,这时候我们真的需要使用一些技巧来将自己的成果进行加密,加壳等办法. ...
- Xbox360游戏收藏
xbox360游戏下载地址 http://dl.3dmgame.com/SoftList_221.html XBLA游戏总结.http://tieba.baidu.com/p/3174478602 ...
- Java字符代码中干掉制表符、回车符和换行符
Java字符代码中干掉制表符.回车符和换行符 代码片段: String sql = StringUtils.trim(sql).replaceAll("[\\r\\n\\t]",& ...
- Web项目中定时任务无法绑定SessionFactory的问题解决
正常我们在web开发中,由于需要在页面上或者脱离事务时使用到懒加载对应的对象,一般都采用Open Session In View模式. Open Session In View OpenSes ...
- HDU1257题解
解题思路:这题的本质就是:求一个给定的数字序列中,非递增(或非递减)子序列的最少的条数. 思维误区:本题很容易被样例坑,以为是直接求跳跃点(i < j && ai < aj ...
- OD 实验(二十一) - 对反调试程序的逆向分析(二)
程序: 运行程序 点击“Verify” 关闭该程序,启动 OD 再运行程序 逆向: 用 OD 载入程序 按 F8 往下走 执行完这个 call 指令就弹出了对话框 这个 call 指令调用了 Dial ...
- [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget (第一部分)
本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-opengl-widget-per-visualizzare-imm ...