[刷题] 104 Maximum Depth of Binary Tree
要求
- 求一棵二叉树的最高深度
思路
- 递归地求左右子树的最高深度
实现
1 Definition for a binary tree node.
2 struct TreeNode {
3 int val;
4 TreeNode *left;
5 TreeNode *right;
6 TreeNode(int x) : val(x), left(NULL), right(NULL) {}
7 };
8
9 class Solution {
10 public:
11 int maxDepth(TreeNode* root) {
12
13 if( root == NULL )
14 return 0;
15
16 return max( maxDepth( root->left ),maxDepth( root->right )) + 1;
17 }
18 };
相关
- 111 Minimum Depth of Binary Tree
[刷题] 104 Maximum Depth of Binary Tree的更多相关文章
- 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 ...
- 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 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 ...
- [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 ...
- (二叉树 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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一: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 ...
随机推荐
- 第十届蓝桥杯大赛软件类省赛C/C++研究生组 试题I:灵能传输
在游戏<星际争霸 II>中,高阶圣堂武士作为星灵的重要 AOE 单位,在游戏的中后期发挥着重要的作用,其技能"灵能风暴"可以消耗大量的灵能对一片区域内的敌军造成毁灭性的 ...
- 软工2021个人阅读作业#2——构建之法和CI/CD的运用
项目 内容 这个作业属于哪个课程 2021学年春季软件工程(罗杰 任健) 这个作业的要求在哪里 2021年软工-热身阅读作业#2 我在这个课程的目标是 了解和掌握现代软件开发和项目管理技术,锻炼在大规 ...
- 深入了解springcloud gateway 的限流重试机制
前言 前面给大家介绍了Spring Cloud Gateway的入门教程,这篇给大家探讨下Spring Cloud Gateway的一些其他功能. Spring Cloud Gateway中的重试 我 ...
- 三、python学习-常用模块
一.常用模块 1.math数学模块 在计算机中,所有数值在计算机底层都是约等于机制,并不是精确地 import math #ceil() 向上取整操作 math.ceil(3.1)=>4 #fl ...
- 浅谈 Fresco 框架结构
在前面的文章 Fresco 源码分析 -- 图片加载流程 里面详细说明了图片加载的整个流程,但是除了理解源码之外,对于源码的框架层面的设计也是需要去了解的,不能只是简单的读源码,好的源码的框架设计也是 ...
- Spring Security OAuth 格式化 token 输出
个性化token 背景 上一篇文章<Spring Security OAuth 个性化token(一)>有提到,oauth2.0 接口默认返回的报文格式如下: { "ac ...
- springboot项目配置logback日志系统
记录springboot项目配置logback日志文件管理: logback依赖jar包 SpringBoot项目配置logback理论上需要添加logback-classic依赖jar包: < ...
- No_leak(ret2ROP + 低字节改写到syscall)
No_leak 有这种题,题目很短小,只有一个read函数,没有输出函数,这样的题怎么解呢?当然首先想到的是ret2dl,但是那个有点儿复杂.下面我来介绍一种简单的解法. 代码如下: //gcc 1. ...
- Javascript图片懒加载
懒加载的意义 懒加载的主要目的是作为服务器前端的优化,减少请求数或延迟请求数. 懒加载的实现 1.第一种是纯粹的延迟加载,使用setTimeOut或setInterval进行加载延迟. 2.第二种是条 ...
- FastAPI + Vue 前后端分离 接口自动化测试工具 apiAutoTestWeb
apiAutoTestWeb使用说明 apiAutoTestWeb是为apiAutoTest的可视化版本,其采用前后端分离(FastAPI + Vue2)方式实现 具体使用: Python3 + Fa ...