704. 二分查找
java
class Solution {
public int search(int[] nums, int target) {
int left = 0, right = nums.length - 1 ;
int cur = (left + right)/2;
while(left <= right){
if(nums[cur] < target){
left = cur + 1;
cur = (left + right)/2;
}else if(nums[cur] > target){
right = cur - 1;
cur = (left + right)/2;
}else{
return cur;
}
}
return -1;
}
}