当前位置:网站首页>[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);
}
};
边栏推荐
- 启动solr报错The stack size specified is too small,Specify at least 328k
- 焱融看 | 混合云时代下,如何制定多云策略
- 学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
- Analysis report on production and marketing demand and investment forecast of global and Chinese diamond powder industry Ⓤ 2022 ~ 2027
- LeetCode重建二叉树详解[通俗易懂]
- Shangtang technology crash: a script written at the time of IPO
- Analysis report on the development prospect and investment strategy of the global and Chinese laser chip industry Ⓑ 2022 ~ 2027
- 1.8 new features list
- leetcode 322. Coin change (medium)
- Analysis report on the development trend and prospect scale of silicon intermediary industry in the world and China Ⓩ 2022 ~ 2027
猜你喜欢

The stack size specified is too small, specify at least 328k

Jenkins+webhooks- multi branch parametric construction-

Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud

详细讲解面试的 IO多路复用,select,poll,epoll

北斗通信模块 北斗gps模块 北斗通信终端DTU

2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!
Reasons for MySQL reporting 1040too many connections and Solutions

学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......

介绍一种对 SAP GUI 里的收藏夹事务码管理工具增强的实现方案

La taille de la pile spécifiée est petite, spécifiée à la sortie 328k
随机推荐
word2vec训练中文词向量
学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
Interpretation of R & D effectiveness measurement framework
5. Use of ly tab plug-in of header component
焱融看 | 混合云时代下,如何制定多云策略
Declare an abstract class vehicle, which contains the private variable numofwheel and the public functions vehicle (int), horn (), setnumofwheel (int) and getnumofwheel (). Subclass mot
Summary of interview questions (1) HTTPS man in the middle attack, the principle of concurrenthashmap, serialVersionUID constant, redis single thread,
盲盒NFT数字藏品平台系统开发(搭建源码)
学会使用LiveData和ViewModel,我相信会让你在写业务时变得轻松
当你真的学会DataBinding后,你会发现“这玩意真香”!
【241. 为运算表达式设计优先级】
Computer network interview knowledge points
Simple two ball loading
Content Audit Technology
Some summary of pyqt5 learning (overview of the general meaning of some signals and methods)
Apache-atlas-2.2.0 independent compilation and deployment
Google Earth Engine(GEE)——全球人类居住区网格数据 1975-1990-2000-2014 (P2016)
Apache-Atlas-2.2.0 独立编译部署
7. Icons
Investment analysis and prospect prediction report of global and Chinese dimethyl sulfoxide industry Ⓦ 2022 ~ 2028