Java Program


  • 0
    L
    public int maxDepth(TreeNode root) {
             if(root == null) return 0;
                
            int countLeft = maxDepth(root.left) + 1;
            int countRight = maxDepth(root.right) + 1;
            
            return countRight > countLeft ? countRight : countLeft;
            
        }
    

Log in to reply
 

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