public class Solution extends VersionControl {
public int firstBadVersion(int n) {
int low = 1, high = n;
while (true) {
if (low >= high) return low;
int medium = low + (high - low) / 2;
if (isBadVersion(medium)) {
high = medium;
} else {
low = medium + 1;
}
}
}
}
LeetCode——278.第一个错误的版本【二分查找(两边条件不同)】
最新推荐文章于 2024-07-30 15:40:41 发布