第23600题 单选题
C++实现有序数组左边界查找的代码横线处应填入哪项?

给定一个长度为 m 的有序数组 nums ,其中可能包含重复元素。下面的函数返回数组中某个元素 target 的左边界,若数组中不包含该元素,则返回 −1 。例如在数组 nums = [5,7,7,8,8,10] 中查找 target=8 ,函数返回8在数组中的左边界的索引。现有如下代码,横线上应填写的代码为( )。

int getLeftBoundary(vector<int>& nums, int target) {
    int left = 0;
    int right = nums.size() - 1;

    while (left < right) {
        int middle = left + ((right - left) / 2);
        if (target <= nums[middle])
            __________________________ // 在此处填入代码
        else
            left = middle + 1;
    }

    return nums[left] == target ? left : -1;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析