依然使用递归思想。

思路:

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;
}

最新文章

  1. linux创建进程fork的方法步骤
  2. 【C#】【Thread】BackgroundWorker的使用
  3. SQLServer存储过程中事务的使用
  4. 如何在ExtJS 6中使用Fashion美化应用程序
  5. SSL/TLS/WTLS原理
  6. loadrunner java 缺少必要的导入包报错
  7. Linux gdb调试入门
  8. Linux下程序崩溃,ulimit,coredump,gdbserver
  9. WebRTC Demo - getUserMedia()
  10. [LeetCode169]Majority Element求一个数组中出现次数大于n/2的数
  11. Java高并发如何解决
  12. Espresso浅析和使用
  13. poj 3070 Fibonacci 矩阵快速幂
  14. 微信自定义菜单url默认80端口问题解决
  15. 腾讯通信云服务端使用心得,腾讯云IM
  16. Oracle 升级的必要性
  17. CSS盒模型及边距问题
  18. ELMO模型(Deep contextualized word representation)
  19. P2678 跳石头题解
  20. .net core实践系列之短信服务-Sikiro.SMS.Api服务的实现

热门文章

  1. SQL查询表结构 相关语句
  2. Python 实现 淘宝秒杀 聚划算 自己主动提醒 源代码
  3. 用C语言编写Windows服务程序的五个步骤
  4. 自定义 DependencyProperty 与 RoutedEvent
  5. 消息队列中点对点与发布订阅区别(good)
  6. Selenium-actions
  7. UwpDesktop!WPF也能开发Surface Dial
  8. vs2017 cordova调试android app
  9. 关于 Apache 2.4 配置PHP时的错误记录
  10. WPF 设置只能运行一个实例