Given a node n on a binary tree, find the longest distance to a leaf node
Anonymous
public int heightOfTree() { return heightUtil(getRoot()); } private int heightUtil(Node root) { if (root == null) { return -1; } int left = heightUtil(root.getLeft()); int right = heightUtil(root.getRight()); return Math.max(left, right) + 1; }
Check out your Company Bowl for anonymous work chats.