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

 

上一篇:Leetcode 918. Maximum Sum Circular Subarray


下一篇:QPropertyAnimation 几行代码快速制作流畅的动画效果