注意:
left<=right
function search( nums , target ) {
let left = 0, right = nums.length-1;
while(left <= right){
let mid = parseInt( (left + right)/2 );
if(nums[mid] < target){//target在右边继续查找
left = mid+1;
}else if(nums[mid] > target){//target在左边继续查找
right = mid-1;
}else{
return mid;
}
}
return -1;
}
module.exports = {
search : search
};