-
-
Save StevenXL/432cb9f1d851e15ebcfcca4990b3addf to your computer and use it in GitHub Desktop.
Maximum Depth of a Binary Tree - Recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function maxDepth(root) { | |
if (!root) { | |
return 0; | |
} else { | |
const leftMaxDepth = maxDepth(root.left); | |
const rightMaxDepth = maxDepth(root.right); | |
return 1 + Math.max(leftMaxDepth, rightMaxDepth); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment