Java solution 1 ms


  • 0
    V
    class Solution {
        public int maxDepth(TreeNode root) {
            if(root == null) 
                return 0;
            else {
                
                int leftNode = maxDepth(root.left);
                int rightNode = maxDepth(root.right);
                
                if(leftNode > rightNode) 
                    return leftNode + 1;
                else
                        return rightNode + 1;
                }
            }
            
        }
    

Log in to reply
 

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