leadcode的Hot100系列--104. 二叉树的最大深度
2024-09-01 00:53:42
依然使用递归思想。
思路:
1、树的深度 = max (左子树深度,右子树深度)+ 1 。 ------> 这里的加1是表示自己节点深度为1。
2、如果当前节点为null,则说明它的左右子树深度为0。
int max(int a, int b)
{
if (a>b)
return a;
else
return b;
}
int maxDepth(struct TreeNode* root){
int iDepth = 0;
if (NULL == root)
return 0;
iDepth = max(maxDepth(root->left), maxDepth(root->right)) + 1;
return iDepth;
}
最新文章
- linux创建进程fork的方法步骤
- 【C#】【Thread】BackgroundWorker的使用
- SQLServer存储过程中事务的使用
- 如何在ExtJS 6中使用Fashion美化应用程序
- SSL/TLS/WTLS原理
- loadrunner java 缺少必要的导入包报错
- Linux gdb调试入门
- Linux下程序崩溃,ulimit,coredump,gdbserver
- WebRTC Demo - getUserMedia()
- [LeetCode169]Majority Element求一个数组中出现次数大于n/2的数
- Java高并发如何解决
- Espresso浅析和使用
- poj 3070 Fibonacci 矩阵快速幂
- 微信自定义菜单url默认80端口问题解决
- 腾讯通信云服务端使用心得,腾讯云IM
- Oracle 升级的必要性
- CSS盒模型及边距问题
- ELMO模型(Deep contextualized word representation)
- P2678 跳石头题解
- .net core实践系列之短信服务-Sikiro.SMS.Api服务的实现