πŸš€ JS | βœ… Max Depth of Binary Tree

#ProblemSolving#binaryTree#JS#leetcode

βœ… Javascript code implementation

var maxDepth = function(root) {
    if (root === null) return 0
    
    let counter = 0
    const goNext = (treeNode, height) => {
        if (treeNode === null) return

        if (treeNode.left === null && treeNode.right === null) {
            if (height > counter) {
                counter = height
            }
        }

        goNext(treeNode.left, height + 1)
        goNext(treeNode.right, height + 1)
    }
    
    
    goNext(root, 1)
    
    return counter
};

πŸ“’Leetcode Solution

πŸš€_Runtime: 63 ms, faster than 34.64% of JavaScript online submissions for Maximum Depth of Binary Tree._ πŸš€_Memory Usage: 45.3 MB, less than 52.05% of JavaScript online submissions for Maximum Depth of Binary Tree._

πŸ“’ Follow on LinkedIn

πŸ“’ Follow on Leetcode