【二分查找】LeetCode 278. 第一个错误的版本
题目链接
思路
二分查找
代码
public class Solution extends VersionControl {
public int firstBadVersion(int n) {
int left = 1, right = n - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (isBadVersion(mid)) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left;
}
}