首页 > 其他 > 详细

[Leetcode] 104. Maximum Depth of Binary Tree

时间:2019-12-08 12:19:19      阅读:100      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

 

 

 1 int depth = 0;
 2     int currentMaxDepth = 0;
 3     public int maxDepth(TreeNode root) {
 4         if(root == null){
 5             return 0;
 6         }
 7         
 8         int leftDepth = 1;
 9         int rightDepth = 1;
10         
11         leftDepth += maxDepth(root.left);
12         
13         rightDepth += maxDepth(root.right);
14         
15         if(leftDepth > rightDepth){
16                 return leftDepth;
17             }
18         else{
19             return rightDepth;
20         }
21     }

 

[Leetcode] 104. Maximum Depth of Binary Tree

原文:https://www.cnblogs.com/seako/p/12005136.html

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