当前位置:网站首页>[force buckle] maximum depth of binary tree
[force buckle] maximum depth of binary tree
2022-07-19 06:26:00 【Patrick star`】
104. The maximum depth of a binary tree - Power button (LeetCode)
subject :
Given a binary tree , Find out the maximum depth .
The depth of a binary tree is the number of nodes in the longest path from the root node to the farthest leaf node .
explain : A leaf node is a node that has no children
Ideas :
Using preorder traversal , Depth of each recursive layer +1
Code :
int maxDepth(struct TreeNode* root)
{
if(root == NULL)
{
return 0;
}
int ldepth = maxDepth(root->left);// The height of the left subtree
int rdepth = maxDepth(root->right);// The height of the right subtree
return ldepth > rdepth ? ldepth + 1:rdepth + 1;
}边栏推荐
猜你喜欢

Introduction to Darwin streaming server

浅谈跨域的几种解决方案

通过VOR深度估计解决三维注视交互中的目标模糊问题
![Chrome browser settings [display the translation language icon in the upper right corner]](/img/87/018e0ab92f698b77ada98ef555bba8.png)
Chrome browser settings [display the translation language icon in the upper right corner]

RestClient查询文档

【力扣】用栈实现队列

【力扣】用队列实现栈

Eye tracking in virtual reality

Cours de mathématiques de base 2 Fonction Euler, écran linéaire, élargissement de l'Europe

Interview review nth time
随机推荐
Acwing daily question three thousand five hundred and eleven
Ehab the Xorcist (异或性质,构造)
Boost dc/dc converter
实习笔试解答
Acwing game 57 (AK)
【力扣】复制带随机指针的链表
Eye tracking in virtual reality
结合图片看常用串口通信UART
2021-11-26 pyautogui cooperates with lightning simulator to realize the automation of mobile app check-in and answer questions
[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....
Volatile function of embedded C language
【力扣】括号匹配
Typescript learning
BusyBox 1.21.1 有udpsvd功能 可以编译成功 不干涉本机busybox方法
XOR-gun (位运算,思维,区间暴力)
Qtss callback routine
MySQL workbench basically uses [create a data table]
Ehab the xorcist (XOR property, construction)
嵌入式C语言重点(const、static、voliatile、位运算)
2022 robocom world robot developer competition - undergraduate group (provincial competition)