Maximum Depth Of Binary Tree - rFronteddu/general_wiki GitHub Wiki

Given the root of a binary tree, return its maximum depth.

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;            
        }
        int left_depth = maxDepth(root.left);
        int right_dept = maxDepth(root.right);
        return Math.max(left_depth, right_dept) + 1;
    }
}