104. Maximum Depth of Binary Tree

time: O(n)

space: O(h)

var maxDepth = function (root) {
    return find(root, 0);
};

function find(node, depth = 0) {
    if (node === null) return depth;
    depth++;
    return Math.max(find(node.left, depth), find(node.right, depth));
}

time: O(n)

space: O(n)

time: O(n)

space: O(h) worst n skewed tree (편향 이진 트리)

Last updated