BM17 二分查找-I
int search(int* nums, int numsLen, int target ) { // write code here int left, right, mid; left = 0; right = numsLen - 1; while (left <= right) { mid = (left + right) / 2; if (nums[mid] == target) return mid; else if (nums[mid] > target) right = mid - 1; else left = mid + 1; } return -1; }