# Easy-题目63：278. First Bad Version

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

Suppose you have n versions [1, 2, …, n] and you want to find out the first bad one, which causes all the following ones to be bad.

You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

// Forward declaration of isBadVersion API.
bool isBadVersion(int version);

class Solution {
public:
int firstBadVersion(int n) {
int low = 1;
int high = n;
int ver = 0;
while (low < high) {
ver = low + (high - low) / 2;
if (isBadVersion(ver)) {
high = ver;
} else {
low = ver + 1;
}
}
return low;
}
};

0ms,beats 3.21%,众数0ms，96.79%。
cmershen的碎碎念：

#### Leetcode_278_First Bad Version

2015-11-08 16:22:58

#### leetcode 278: First Bad Version

2015-09-08 08:49:49

#### [LeetCode-278] First Bad Version（二分法注意事项）

2015-09-29 14:58:42

#### 278. First Bad Version

2016-01-06 00:18:53

#### 278. First Bad Version*

2017-01-09 20:35:44

#### 278.[LeetCode]First Bad Version

2016-08-16 14:25:23

#### 【LeetCode】 278. First Bad Version

2016-12-24 07:52:21

#### [LeetCode]--278. First Bad Version

2016-10-16 09:41:17

#### leetcode - 278. First Bad Version

2018-02-26 14:29:54

#### LeetCode *** 278. First Bad Version

2016-04-10 20:28:26