首页 > 其他 > 详细

面试39---二叉树的深度

时间:2018-05-09 14:10:50      阅读:163      评论:0      收藏:0      [点我收藏+]

题目链接

求解二叉树的深度,延伸可见leetcode110题。

法一:dfs。

技术分享图片
1     private int TreeDepth(TreeNode root) {
2         if(root == null) {
3             return 0;
4         }
5         int l = TreeDepth(root.left);
6         int r = TreeDepth(root.right);
7         return (l > r) ? (l + 1) : (r + 1);
8     }
View Code

 

面试39---二叉树的深度

原文:https://www.cnblogs.com/cing/p/9013334.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!