private int getHeight(TreeNode node) {
        if (node == null) return 0;
        int l = getHeight(node.left);
        int r = getHeight(node.right);
        if (l < 0 || r < 0) {
            return -1;
        }
        if (Math.abs(l - r) > 1) {
            return -1;
        }
        return 1 + Math.max(l, r);
    }