104. Maximum Depth of Binary Tree
class Solution {
public int maxDepth(TreeNode root) {
if(root==null) return 0;
//postorder
int leftHeight = maxDepth(root.left);
int rightHeight = maxDepth(root.right);
return Math.max(leftHeight, rightHeight)+1;
}
}
Last updated
Was this helpful?