题解 | 二分查找-I
二分查找-I
https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b
#include <stdio.h>
int search(int* nums, int numsLen, int target ) {
// write code here
int low = 0, hight = numsLen-1;
while(low<=hight){
int mid = (low+hight)/2;
if(nums[mid] == target){
return mid;
}else if(nums[mid] < target){
low++;
}else {
hight--;
}
}
return -1;
}
