其他分享
首页 > 其他分享> > [Leetcode] 104. Maximum Depth of Binary Tree

[Leetcode] 104. Maximum Depth of Binary Tree

作者:互联网

 

 

 

 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     }

 

标签:Binary,return,int,leftDepth,Tree,Maximum,rightDepth,maxDepth,root
来源: https://www.cnblogs.com/seako/p/12005136.html