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.

Note: A leaf is a node with no children.

Example:

Given binary tree [3,9,20,null,null,15,7],

    3
/ \
9 20
/ \
15 7

return its depth = 3.

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == NULL) return ; return max(maxDepth(root->left), maxDepth(root->right)) + ;
}
};

LeetCode 104. Maximum Depth of Binary Tree(二叉树深度)的更多相关文章

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

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

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

  3. LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java

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

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

  5. Leetcode 104 Maximum Depth of Binary Tree 二叉树

    计算二叉树的最大深度 我的方法是找出两个子树的长度中最长的那个,然后加1 class Solution { public: int maxDepth(TreeNode* root) { ; ,maxD ...

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

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

  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 (二叉树的最大深度)

    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 long ...

  10. 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 ...

随机推荐

  1. C#各版本新增功能

    本系列文章主要整理并介绍 C# 各版本的新增功能. C# 8.0 C#8.0 于 2019年4月 随 .NET Framework 4.8 与 Visual Studio 2019 一同发布,但是当前 ...

  2. [图解]Windows下使用Zend Studio 10和XAMPP 1.8搭建开发环境,ZendFramework 2 HelloWorld

    1.下载并安装 ZendStudio,搜一个破解版 XAMPP,官网下载:https://www.apachefriends.org/index.html 2.打开ZendStudio新建一个php项 ...

  3. 项目Beta冲刺(团队6/7)

    项目Beta冲刺(团队) --6/7 作业要求: 项目Beta冲刺(团队) 1.团队信息 团队名 :男上加男 成员信息 : 队员学号 队员姓名 个人博客地址 备注 221600427 Alicesft ...

  4. python + redis +ipset实现IP黑名单的动态添加及解封禁

    1.抽空用python做了一个 动态添加/删除IP黑名单 的程序(或者说实现方案),项目地址: https://gitee.com/lowmanisbusy/ip_blacklists, 2.这里的实 ...

  5. pytcharm无法debug:pydev debugger: process 15188 is connecting

    今天问老师,老师说需要设置断点,果然设置断点后就可以正常调试了.

  6. SecureCRT 日记保存带时间戳

    %h:%m:%s:%t--- result:

  7. Cronicle 基于nodejs 的分布式任务调度工具

    Cronicle 是一款不多的分布式任务调度工具,基于nodejs 开发,同时包含看web UI,从官方介绍看到的UI还是 挺不错的,而且功能很丰富,值得试用下 参考资料 http://cronicl ...

  8. pmm 添加proxysql metrics

    pmm 对于proxysql 的管理是基于metrics的进行处理的,使用的是proxysql exporter 对于proxysql exporter的添加,比较简单,我们可以通过独立的额容器运行e ...

  9. prisma2 预览版

    prisma2 预览版已经发布好几个版本了,同时官方的参考文档也在github 可以看到 新版本的架构变动 参考图 说明 photon 为一个类型安全的数据库客户端(替换orm) lift 数据模型的 ...

  10. 字典树(Trie)学习笔记

    目录 什么是字典树 如何存储字典树 如何查找字符串有没有出现 第一个图的那种线段树 应用 例题 1.统计难题 2.P2580 于是他错误的点名开始了 什么是字典树 上图来自luogu题解 这是一种字典 ...