Created
November 2, 2016 02:41
-
-
Save dgodfrey206/7f009ce4c9bdc0e0bcefbc7324f87f30 to your computer and use it in GitHub Desktop.
Height of binary tree
This file contains hidden or 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
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