704. 二分查找 + 二分法
704. 二分查找
LeetCode_704
题目描述
代码实现
class Solution {
public int search(int[] nums, int target) {
int low = 0, high = nums.length - 1;
while(low <= high){
int mid = (low + high) >> 1;
if(nums[mid] == target){
return mid;
}else if(nums[mid] < target){
low = mid + 1;
}else{
high = mid- 1;
}
}
return -1;
}
}
Either Excellent or Rusty