You are are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each of the version is developed based on the previous version and all of the versions after a bad version are bad.
Suppose you have n versions [1, 2, ..., n] and you want to find out the "the" one, which causes all the following ones T O is bad.
You are are given an API bool Isbadversion (version) which would return whether version are bad. Implement a function to find the "the" You are should minimize the number of calls to the API.
This topic is very simple, direct two-point search
public class Solution extends VersionControl {public
int firstbadversion (int n) {
int lo = 1, hi = N;
while (Lo < hi) {
int med = lo + (hi- lo)/2;
if (Isbadversion (med)) {
hi = med;
} else {
lo = med + 1;
}
}
return lo;
}
}