Solution:
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
long long start=0,end=n,mid;
while(end-start>1)
{
mid=(start+end)/2;
if(isBadVersion(mid))
end=mid;
else
start=mid;
}
return end;
}
};
Top comments (0)