1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @Title: 第一个错误的版本 (First Bad Version)
// @Author: 15816537946@163.com
// @Date: 2020-06-25 07:15:36
// @Runtime: 12 ms
// @Memory: 33.1 MB
/* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */

public class Solution extends VersionControl {
        public int firstBadVersion(int n) {
    int left = 1;
    int right = n;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (isBadVersion(mid)) {
            right = mid-1;
        } else {
            left = mid + 1;
        }
    }
    return left;
}
    }