leetcode 278 First Bad Version(第一個錯誤的版本)C 二分法

NO IMAGE
// Forward declaration of isBadVersion API.
bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
int start = 1, end = n;
while (start < end) {
int mid = start   (end-start) / 2;   // 總是取中間數,或者中間數-0.5
if (!isBadVersion(mid)) start = mid   1;
else end = mid;            
}        
return start;
}
};