You are viewing a single comment's thread. Return to all comments →
My Java solution w/ linear time and o(h) space:
public static int height(Node root) { if(root == null) return -1; //no height int leftHeight = height(root.left); int rightHeight = height(root.right); return 1 + Math.max(leftHeight, rightHeight); }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
My Java solution w/ linear time and o(h) space: