278. 第一个错误的版本
作者:互联网
思路:
相当于转化成查找第一个true,直接二分搜索即可。
简单题我重拳出击
代码:
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
long long left = 0,right = n;
while(left<right){
long long mid = (left+right)/2;
bool res = isBadVersion(mid);
if(res){
right = mid;
}
else if(!res){
left = mid+1;
}
}
return left;
}
};
标签:right,错误,int,isBadVersion,long,defined,版本,278,left 来源: https://www.cnblogs.com/Mrsdwang/p/14881004.html