当前位置:网站首页>[sword finger offer] 55 - I. depth of binary tree
[sword finger offer] 55 - I. depth of binary tree
2022-07-01 13:39:00 【LuZhouShiLi】
The finger of the sword Offer 55 - I. The depth of the binary tree
subject
Enter the root node of a binary tree , Find the depth of the tree . The nodes that pass from the root node to the leaf node ( Containing root 、 Leaf nodes ) A path to a tree , The length of the longest path is the depth of the tree .
Ideas
Nodes have both left and right subtrees , Then the depth of the tree is the larger value of the depth of the left and right subtrees plus 1.
Code
/** * 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 == nullptr)
{
return 0;
}
int left = maxDepth(root->left);
int right = maxDepth(root->right);
return (left > right) ? (left + 1) :(right + 1);
}
};
边栏推荐
- Asp. NETCORE uses dynamic to simplify database access
- 当你真的学会DataBinding后,你会发现“这玩意真香”!
- MySQL Replication中的并行复制示例详解
- leetcode 322. Coin change (medium)
- Qtdeisgner, pyuic detailed use tutorial interface and function logic separation (nanny teaching)
- MySQL六十六问,两万字+五十图详解!复习必备
- spark源码(五)DAGScheduler TaskScheduler如何配合提交任务,application、job、stage、taskset、task对应关系是什么?
- Leetcode question 1: sum of two numbers (3 languages)
- 机器学习总结(一):线性回归、岭回归、Lasso回归
- Google Earth Engine(GEE)——全球人类居住区网格数据 1975-1990-2000-2014 (P2016)
猜你喜欢

焱融看 | 混合云时代下,如何制定多云策略

2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!

流量管理技术

2022 · 让我带你Jetpack架构组件从入门到精通 — Lifecycle

B站被骂上了热搜。。
![[machine learning] VAE variational self encoder learning notes](/img/38/3eb8d9078b2dcbe780430abb15edcb.png)
[machine learning] VAE variational self encoder learning notes

Qtdeisgner, pyuic detailed use tutorial interface and function logic separation (nanny teaching)

Colorful five pointed star SVG dynamic web page background JS special effect

启动solr报错The stack size specified is too small,Specify at least 328k
![[development of large e-commerce projects] performance pressure test - basic concept of pressure test & jmeter-38](/img/50/819b9c2f69534afc6dc391c9de5f05.png)
[development of large e-commerce projects] performance pressure test - basic concept of pressure test & jmeter-38
随机推荐
Analysis report on production and marketing demand and investment forecast of global and Chinese diamond powder industry Ⓤ 2022 ~ 2027
[241. Design priority for operation expression]
Global and Chinese n-butanol acetic acid market development trend and prospect forecast report Ⓧ 2022 ~ 2028
Terminal identification technology and management technology
ArrayList扩容机制以及线程安全性
北斗通信模块 北斗gps模块 北斗通信终端DTU
Blind box NFT digital collection platform system development (build source code)
刘对(火线安全)-多云环境的风险发现
Yarn重启applications记录恢复
流量管理技术
Flow management technology
10. Page layout, guess you like it
Grafana reports an error: error= "failed to send notification to email addresses: [email protected] : 535 Error:
2.15 summary
开源者的自我修养|为 ShardingSphere 贡献了千万行代码的程序员,后来当了 CEO
Use of shutter SQLite
arthas使用
Explain IO multiplexing, select, poll, epoll in detail
3.4 data query in introduction to database system - select (single table query, connection query, nested query, set query, multi table query)
一款Flutter版的记事本