class Solution {
public:
int firstBadVersion(int n) {
int l=1;
int r=n;
int mid=1/2+n/2;
while(r>=l)
{
if(!isBadVersion(mid)&&isBadVersion(mid+1))
{
mid= mid+1;
break;
}
else if(isBadVersion(mid)&&!isBadVersion(mid-1))
{
break;
}
else if(isBadVersion(mid))
{
r=mid-1;
mid=r/2+l/2;
}
else if(!isBadVersion(mid))
{
l=mid+1;
mid=r/2+l/2;
}
}
return mid;
}
};
加油!