Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/30-binary-search-trees/problem
- static int getHeight(Node root){
- //Write your code here
- int result = getHelp(0, root);
- return result;
- }
- static int getHelp(int level, Node root){
- int right = 0, left = 0;
- if(root.left != null){
- left = getHelp(level+1, root.left);
- }
- if(root.right != null){
- right = getHelp(level+1, root.right);
- }
- return right > left ? right : left;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement