function search_bak(nums: number[], target: number): number {
// 记录索引位置
let start = 0;
let end = nums.length;
let i =10;
let a = null;
while(--i>0){
let temp = Math.floor((start+end)/2);
if(a!=temp){
a=temp;
// console.log(`a:${a}-start:${start}end:${end}`)
if(target == nums[a]){
return a;
}
if(target > nums[a]){
start = a;
}else{
end = a;
}
}else{
return -1;
};
}
};
function search(nums: number[], target: number): number {
const n = nums.length
let l = 0, r = n - 1
while (l <= r) {
const mid = (l + r) >> 1
if (nums[mid] == target) return mid
if (nums[mid] > target) {
r = mid - 1
} else {
l = mid + 1
}
}
return -1
};
console.log(search([-1,0,3,5,9,12],9))
console.log(search([-1,0,3,5,9,12],2))
console