LeetCode: Maximum Depth of Binary Tree Solution

Explanation is hard

Implementation

1var maxDepth = function (root) {
2 if (!root) return 0
3
4 return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1
5}

References

Original problem

Similar problems

Balanced Binary Tree

Minimum Depth of Binary Tree

Maximum Depth of N-ary Tree

Time Needed to Inform All Employees

Amount of Time for Binary Tree to Be Infected

Comments

Loading comments...

Tags

leetcode

tree

binary tree

recursion

Next Post

LeetCode: Diameter of Binary Tree

Sum of max height of 2 subtrees

Previous Post

LeetCode: Balanced Binary Tree

Modified version of "Maximum Depth of Binary Tree"

HoningJS

Search Posts