public boolean isBalanced(TreeNode root) {
        
        if(root == null)
            return true;
        
        int left = height(root.left);
        int right = height(root.right);

        if (left < 0 || right < 0)
            return false;

        if (left < right - 1 || left > right + 1)
            return false;

        return true;

    }