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 ...
随机推荐
- centos6.6升级安装MySQL5.5(2015/3/4)
使用系统CentOS 6.6本来已经系统自带安装了mysql 5.1,但是奈何5.1不支持utf8mb4字符集(详见:http://blog.csdn.net/shootyou/article/det ...
- Java API 操作Zookeeper
一.依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...
- qing-automation简单入门介绍
1.相关文档:http://www.51testing.com/html/50/category-catid-250.html 2.进行Qing automation相关操作之前,必须安装好jdk跟a ...
- Apache DBUtils使用总结 【转】
Apache DBUtils使用总结 DBUtils是个小巧的JDBC轻量级封装的工具包,其最核心的特性是结果集的封装,可以直接将查询出来的结果集封装成JavaBean,这就为我们做了最枯燥乏味. ...
- 在Google的GKE上创建支持Internal Load Balancer的Service
在Google的Kubernetes Engine上发布service,可以采用除On-Promise相同的Cluster IP和NodePort两种方式外,还可以创建LoadBalaner的Serv ...
- table tr列 鼠标经过时更改背景颜色
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 黄聪:WordPress默认编辑器可视化切换不见了,非插件导致消失问题
1.后台---用户---我的个人资料 2.看看 [可视化编辑器]的[撰写文章时不使用可视化编辑器]项目是不是勾上了 3.去掉保存即可
- 使用maven打包额外的jar
当使用maven打包的时候,部分自己的额外使用的在maven基础库里面是没有的时候: 参考: https://blog.csdn.net/hguisu/article/details/5107268 ...
- Ajax显示隐藏
$(function(){ $('#search').click(function(){ if($(".search_div").is(":visible")) ...
- Java:类与继承(隐藏和覆盖的问题)
盒子先生金金 Java:类与继承(隐藏和覆盖的问题) Java:类与继承 Java:类与继承 对于面向对象的程序设计语言来说,类毫无疑问是其最重要的基础.抽象.封装.继承.多态这四大特性都离不 ...