Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. int height(Node* root) {
  2. // Write your code here.
  3. if (root == NULL)
  4. return 0;
  5.  
  6. // find the height of each subtree
  7. int lh = height(root->left);
  8. int rh = height(root->right);
  9.  
  10. return max(lh,rh)+1;
  11. }
  12.  
  13. int height(Node* root) {
  14. if (root == NULL) return 0;
  15. if (root ->left== NULL && root->right== NULL)
  16. return 0;
  17.  
  18. // find the height of each subtree
  19. int lh = height(root->left);
  20. int rh = height(root->right);
  21.  
  22. return max(lh,rh)+1;
  23.  
  24. // Write your code here.
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement