704. 二分查找
问题描述:
解答:
class Solution {
public int search(int[] nums, int target) {
int low=0,high=nums.length-1;
while(low<=high){
int mid =(high-low)/2+low;
int num = nums[mid];
if(num==target){
return mid;
}else if(num > target){
high=mid-1;
}else{
low=mid+1;
}
}
return -1;
}
}
思路:
278. 第一个错误的版本
问题描述:
解答:
public class Solution extends VersionControl {
public int firstBadVersion(int n) {
int low = 1, high = n;
while(low
思路:
35. 搜索插入位置
问题描述:
解答:
class Solution {
public int searchInsert(int[] nums, int target) {
int low=0,high=nums.length-1,mid=0;
while(low<=high){
mid = (high-low)/2+low;
if(nums[mid]target){
high = mid-1;
}else{
return mid;
}
}
return low;
}
}
思路:



