Really simple and clean JAVA solution


  • 1
    Z
    public int maxDepth(TreeNode root) {
        
     return getDepth(root);
        
    }
    
    public int getDepth(TreeNode root){
        if(root==null){
            return 0;
        }
        
        int l = getDepth(root.left);
        int r = getDepth(root.right);
        
        return Math.max(l,r)+1;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.