here's my code

```
public int firstBadVersion(int n) {
int left = 1, right = n;
int min = n;
while (left < right) {
int mid = left + (right - left) / 2;
boolean bad = isBadVersion(mid);
if (bad) {
min = Math.min(min, mid);
right = mid;
} else {
left = mid + 1;
}
}
return min;
}
```