A27068. 下面的C++ 代码用于在升序数组 lst 中查找⽬标值 target 最后一次出现的位置。相关说法,正确的是( )。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…
单选题
困难
知识点
题目描述
下面的C++ 代码用于在升序数组 lst 中查找⽬标值 target 最后一次出现的位置。相关说法,正确的是( )。
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;
}选项(单选)
答案解析
详细答案解析为会员权益,按每日次数查看。
开通 / 升级会员
上一题
下一题