TheAlgorithms-C/leetcode/src/278.c

16 lines
339 B
C
Raw Normal View History

2019-09-26 23:29:31 +08:00
// 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;
}