Description
Submission
// The API isBadVersion is defined for you. // bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { int l = 1; int r = n; int m = (r - l) / 2 + l; for(; l <= r; m = (r - l) / 2 + l) { if(isBadVersion(m)) { r = m -1; } else { l = m + 1; } } if(isBadVersion(min(l, r))) return min(l ,r); return max(l, r); } };