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. web 优化原则

    1. 减少http 请求   2. 使用CDN   3. 添加expires 头   4. gzip 压缩   5. 样式表放在头部   6. 脚本放底部   7. 避免css 表达式   8. 使用 ...

  2. RK3288 usb 摄像头旋转

    系统:Android 5.1 下面实现了摄像头 180 度旋转,旋转角度只需修改 orientation. diff --git a/hardware/rockchip/camera/CameraHa ...

  3. centos65安装docker遇到的问题

    1.安装docker后启动显示内核太低(升级内核): 网上太多方案 2.升级内核后还是启动不了docker:执行下面语句 yum install device-mapper-event-libs 步骤 ...

  4. HBase之八--(3):Hbase 布隆过滤器BloomFilter介绍

    布隆过滤器( Bloom filters) 数据块索引提供了一个有效的方法,在访问一个特定的行时用来查找应该读取的HFile的数据块.但是它的效用是有限的.HFile数据块的默认大小是64KB,这个大 ...

  5. 第七章 伪分布式安装hive,sqoop

    第一部分:先讲这么去安装hive.先去hive官网下载,我这里以hive-0.12.0为例子. 前面第二章讲了安装hadoop,hbase实例,我们继续讲这么安装hive,先说下hive配置文件 一, ...

  6. OpenCV for Python常用命令

      读取图像首先要导入OpenCV包 import cv2 OpenCV目前支持读取bmp.jpg.png.tiff等常用格式. //读取图片 img2 = cv2.imread('out-0022. ...

  7. 生成短的uuid

    package test1; import java.util.Random; import java.util.UUID; public class ShareCodeUtil { private ...

  8. PHP5.3安装Zend Guard Loader代替Zend Optimizer

    Zend Optimizer/3.3.3   解密加代码优化,提高PHP应用程序的执行速度,显著降低服务器的CPU负载. Zend Guard Loader/5.5.0/6.0   解密加代码优化,提 ...

  9. Varnish,Nginx搭建缓存服务器

    Varnish,Nginx搭建缓存服务器 一. varnish 1.安装pcre库,兼容正则表达式 # tar -zxvf pcre-8.10.tar.gz # cd pcre-8.10 # ./co ...

  10. ubuntu下用expect实现密码自动输入

    每次笔记本一开机启动,总会连用不着且碍事的触摸板也一块启动.便想写个脚本,让电脑启动时关闭触摸板.(当然,我想更好的办法是,修改系统启动时的加载模块,让触摸板不自动加载,但是目前还不知道用这种方法怎么 ...