Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 9, 2016 23:57
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 jianminchen/18de7257b29bf6ccbab63cdc93d4077f to your computer and use it in GitHub Desktop.
Save jianminchen/18de7257b29bf6ccbab63cdc93d4077f to your computer and use it in GitHub Desktop.
HackerRank - Tree - height of tree
/*The tree node has data, left child and right child
struct node
{
int data;
node* left;
node* right;
};
*/
int height(node * root)
{
if(root==NULL)
return 0;
if(root!=NULL && root->left==NULL && root->right==NULL)
return 0;
int hl = height(root->left);
int hr = height(root->right);
return hl>=hr?(1+hl):(1+hr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment