2021.09.16 - 043.第一个错误的版本
作者:互联网
文章目录
1. 题目
2. 思路
(1) 二分查找
- 注意!查找分界线时终止条件的判断符号是<,根据需要,最终left=right=分界线的左侧或右侧。
3. 代码
public class Test {
public static void main(String[] args) {
}
}
class VersionControl {
boolean isBadVersion(int version) {
return true;
}
}
class Solution extends VersionControl {
public int firstBadVersion(int n) {
int left = 1;
int right = n;
int mid;
while (left < right) {
mid = left + ((right - left) >>> 1);
if (isBadVersion(mid)) {
right = mid;
} else {
left = mid + 1;
}
}
return right;
}
}
标签:right,16,int,2021.09,mid,class,043,public,left 来源: https://blog.csdn.net/qq_44021223/article/details/120326592