We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
// Write your code here.
if ((root->left!=NULL) && (root->right!=NULL)){
int a = height(root->left) + 1;
int b = height(root->right) + 1;
return max(a, b);
}
if (root->left!=NULL) return height(root->left) + 1;
if (root->right!=NULL) return height(root->right) + 1;
return 0;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
simple C++ solution:
int height(Node* root) {