Untitled
unknown
plain_text
a year ago
331 B
5
Indexable
public int maxDepth(TreeNode root) {
if (root == null) return 0; // Base case: Empty tree
int leftDepth = maxDepth(root.left); // Depth of left subtree
int rightDepth = maxDepth(root.right); // Depth of right subtree
return 1 + Math.max(leftDepth, rightDepth); // Add 1 for the current node
}Editor is loading...
Leave a Comment