Skip to content

Instantly share code, notes, and snippets.

@StevenXL
Created March 10, 2020 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenXL/432cb9f1d851e15ebcfcca4990b3addf to your computer and use it in GitHub Desktop.
Save StevenXL/432cb9f1d851e15ebcfcca4990b3addf to your computer and use it in GitHub Desktop.
Maximum Depth of a Binary Tree - Recursive
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