第20735题 单选题
下列关于实现升序数组查找目标值最后一次出现位置的C++二分查找代码的说法,正确的是?
int binary_search_last_occurrence(const vector<int>& lst, int target) {    
    if (lst.empty()) return -1;    
    int low = 0, high = lst.size() - 1;    
    while (low < high) {        
        int mid = (low + high + 1) / 2;        
        if (lst[mid] <= target) {            
            low = mid;        
        } else {            
            high = mid - 1;        
        }    
    }    
    if (lst[low] == target)        
        return low;    
    else        
        return -1;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析