All pastes #2052600 Raw Edit

Unnamed

public java v1 · immutable
#2052600 ·published 2011-05-01 19:02 UTC
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);    }