Skip to content

Instantly share code, notes, and snippets.

@pratyushcrd
Created January 13, 2018 11:14
Show Gist options
  • Save pratyushcrd/6c2366c1266f0d46e08582398e22b982 to your computer and use it in GitHub Desktop.
Save pratyushcrd/6c2366c1266f0d46e08582398e22b982 to your computer and use it in GitHub Desktop.
function height (node) {
if (!node) {
return 0
}
var leftHeight = height(node.left)
var rightHeight = height(node.right)
if (leftHeight > rightHeight) {
return leftHeight + 1 // Adding 1 for considering node's height
} else {
return rightHeight + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment