Maximum Depth of Binary Tree | LeetCode 104

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard

Here is the full implementation.

let maxDepth = function(root) {    
    let maxNodes = (node, sum) => {
        if (node === null) {
            return sum;
        }
        
        return Math.max(maxNodes(node.left, sum + 1), maxNodes(node.right, sum + 1));
    }
    
    return maxNodes(root, 0);
};