public TreeNode sortedArrayToBST(int[] num) {
        int n = num.length - 1;
        if (n<0) return null;
        int mid = n / 2;
        TreeNode root = new TreeNode(num[mid]);
        doInsert(num, 0, mid - 1, root, true);
        doInsert(num, mid + 1, n, root, false);
        return root;
    }