class Solution {
public int search(int[] nums, int target) {
int l=0;
int r=nums.length-1;
while(l<=r){
int mid=l + ((r - l) / 2); //注意mid在while循环里面!!!因为时时都要变化
if(target<nums[mid]){
r=mid-1;
}
else if(target>nums[mid]){
l=mid+1;
}
else{
return mid;
}
}
return -1;
}
}