A simple accepted solution with Java


  • 0
    F

    public int maxDepth(TreeNode root) {
    return dfs(root, 0);
    }

    private int dfs(TreeNode x, int d) {
        if (x == null) return d;
        return Math.max(dfs(x.left, d + 1), dfs(x.right, d + 1));
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.