104. Maximum Depth of Binary Tree (Tree)

easy

 

 1 class Solution {
 2    public int maxDepth(TreeNode root) {
 3        if(root != null) {
 4            int left = maxDepth(root.left); 
 5            int right = maxDepth(root.right);
 6            return Math.max(left, right) + 1;
 7            
 8        }else {
 9            return 0;
10        }
11        
12    }
13 }

 

posted @ 2018-08-28 22:01  jasoncool1  阅读(91)  评论(0编辑  收藏  举报