
π 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