278. First Bad Version#

Approach/Intuition

Binary Search

 1public int firstBadVersion(int n) {
 2  int left = 0;
 3  int right = n;
 4
 5  while (left < right) {
 6    int mid = left + (right - left) / 2;
 7    if (isBadVersion(mid)) {
 8      right = mid;
 9    } else {
10      left = mid + 1;
11    }
12  }
13
14  return left;
15}