rendered paste body public int height(Node n) { if (n == null) { return 0; } int lh = height(n.left); int rh = height(n.right); return 1 + ((lh > rh) ? lh : rh); } public boolean balanced(Node n) { if (n == null) { return true; } //left balanced and right balanced and absolute difference between subtrees is <= 1 return balanced(n.left) && balanced(n.right) && (Math.abs(height(n.left) - height(n.right)) <= 1); } public boolean balanced(){ return balanced(root); } public int height() { return height(root); }