现在开始刷代码随想录里的题了。
int search(int* nums, int numsSize, int target) {
int head=0,tail=numsSize-1;
while(head<=tail){
int mid=(head+tail)/2;
if(nums[mid]<target){
head=mid+1;
}else if(nums[mid]>target){
tail=mid-1;
}else{
return mid;
}
}
return -1;
}
没啥好说的,太基础了。
结果:
标签:二分,numsSize,return,704,mid,int,tail,查找 From: https://www.cnblogs.com/llllmz/p/18034692