刚学c语言,题目意思没弄懂,不知道为啥,,把主函数写上就错.
int search(int* nums, int numsLen, int target)
{
if(numsLen == 0)
{
return -1;
}
int left = 0;
int right = numsLen - 1;
while (left <= right)
{
int mid = (left + right) / 2;
if (nums[mid] > target)
{
right = mid - 1;
}
else if (nums[mid] < target)
{
left = mid + 1;
}
else
{
return mid;
}
}
return -1;
}