mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
16 lines
339 B
C
16 lines
339 B
C
// Forward declaration of isBadVersion API.
|
|
bool isBadVersion(int version);
|
|
|
|
int firstBadVersion(int n) {
|
|
int low = 1, high = n;
|
|
while (low <= high) {
|
|
int mid = low + (high - low) / 2;
|
|
if(isBadVersion(mid)) {
|
|
high = mid - 1;
|
|
} else {
|
|
low = mid + 1;
|
|
}
|
|
}
|
|
return low;
|
|
}
|