Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created November 2, 2016 02:41
Show Gist options
  • Save dgodfrey206/7f009ce4c9bdc0e0bcefbc7324f87f30 to your computer and use it in GitHub Desktop.
Save dgodfrey206/7f009ce4c9bdc0e0bcefbc7324f87f30 to your computer and use it in GitHub Desktop.
Height of binary tree
int height(node* root) {
if (!root) return 0;
int leftHeight = 0, rightHeight = 0;
if (root->left)
leftHeight = 1 + height(root->left);
if (root->right)
rightHeight = 1 + height(root->right);
return max(leftHeight, rightHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment