#GESP4277. [GESP]L5-202609-Q4277-S

[GESP]L5-202609-Q4277-S

在升序数组中查找第一个严格大于 x 的元素位置,下面代码中的横线应填写( )。

int upperBound(const vector<int> &a, int x) {
    int l = 0, r = (int)a.size();
    while (l < r) {
        int mid = l + (r - l) / 2;
        if (__________________) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    return l;
}

{{ select(1) }}

  • a[mid] < x
  • a[mid] >= x
  • a[mid] <= x
  • a[mid] > x