/**
* class SVNRepo {
* public:
* static bool isBadVersion(int k);
* }
* you can use SVNRepo::isBadVersion(k) to judge whether
* the kth code version is bad or not.
*/
class Solution {
public:
/**
* @param n: An integers.
* @return: An integer which is the first bad version.
*/
int findFirstBadVersion(int n) {
// write your code here
if(n <= 0) {
return 0;
}
int low = 1, high = n;
while(low <= high) {
int mid = low + (high - low) / 2;
if(SVNRepo::isBadVersion(mid)) {
high = mid - 1;
}
else {
low = mid + 1;
}
}
return low;
}
};
Lintcode 第一个错误版本
最新推荐文章于 2020-03-04 22:02:00 发布