Max Depth of Binary Tree
Maximum Depth of Binary Tree (LC.104)
Example
+ 1
/ \
2 3
/ \
4 5
Max depth: 3Analysis
Code
public int maxDepth(TreeNode root) {
// base case
if (root == null)
return 0;
// divide
int leftSubtree = maxDepth(root.left);
int rightSubtree = maxDepth(root.right);
// conquer
return 1 + Math.max(leftSubtree, rightSubtree);
}Minimum Depth of Binary Tree (LC.111)
Example
Analysis
Code
Last updated