Maximum Depth of Binary Tree
Thoughts
Code
public class Solution {
/**
* @param root: The root of binary tree.
* @return: An integer.
*/
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
int left = maxDepth(root.left);
int right = maxDepth(root.right);
return Math.max(left, right) + 1;
}
}Analysis
Ver. 2
PreviousConvert Sorted Array to Binary Search TreeNext1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree
Last updated