TheAlgorithms-C/leetcode/src/35.c
2019-08-07 17:00:30 -07:00

14 lines
347 B
C

int searchInsert(int* nums, int numsSize, int target){
int low = 0, high = numsSize - 1, mid;
while (low <= high) {
mid = low + (high - low) / 2;
if (target > nums[mid])
low = mid + 1;
else if (target < nums[mid])
high = mid - 1;
else
return mid;
}
return low;
}