search until you find the first bad version.

```
bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
int start = 1, end = n;
while (start < end) {
int mid = start + (end - start)/2;
if (isBadVersion(mid)) end = mid;
else start = mid + 1;
}
return end;
}
};
```