思路:
// @Title: 第一个错误的版本 (First Bad Version)
// @Author: qisiii
// @Date: 2022-02-26 11:56:41
// @Runtime: 20 ms
// @Memory: 38.1 MB
// @comment:
// @flag:
/* The isBadVersion API is defined in the parent class VersionControl.
boolean isBadVersion(int version); */
public class Solution extends VersionControl {
public int firstBadVersion(int n) {
int left=1,right=n;
while(left<=right){
int mid=left+(right-left)/2;
if(isBadVersion(mid)){
right=mid-1;
}else{
left=mid+1;
}
}
return left;
}
}