## LeetCode：First Bad Version - 第一个坏版本 原

北风其凉

1、题目名称

2、题目地址

3、题目内容

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.

4、解题方法

``````/**
* 功能说明：LeetCode 278 - First Bad Version
* 开发人员：Tsybius2014
* 开发时间：2015年9月13日
*/
public class Solution extends VersionControl {

/**
* 找到第一个坏版本
* @param n 总版本数
* @return 第一个坏版本的序号
*/

if (n <= 0) {
return 0;
}

return 1;
return Integer.MAX_VALUE;
}

int left = 1;
int right = n;

int mid;
while (true) {
mid = left + (right - left) / 2; //注意 left + right 有可能超过了整数的最大值
if (mid == left) {
return right;
}
right = mid;
} else {
left = mid;
}
}
}
}``````

END

### 北风其凉

278. First Bad Version - LeetCode

Question 278. First Bad Version Solution 题目大意：产品有5个版本1，2，3，4，5其中下一个版本依赖上一个版本，即版本4是坏的，5也就是坏的，现在要求哪个版本是第一个坏的。 思路：二分法...

yysue
2018/08/07
0
0

2018/12/13
0
0

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......

woshixin
2018/12/12
0
0

u013553529
2017/11/25
0
0
Leetcode日记7

（2015/1/2） LeetCode 318 Maximum Product of Word Lengths 题目： 1）求一个字符串数组中，两个不同的字符串的长度乘积的最大值。 2）这两个字符串不能共同拥有同一个字符。（两个字符串的...

fxdhdu
2016/01/03
48
0

import java.util.Arrays; public class Solution { public int MoreThanHalfNum_Solution(int [] array) { Arrays.sort(array); int count=0; for(int i=0;i<array.le......

8分钟前
0
0

Gemini-Lin
24分钟前
0
0
Python开发工具:Webware for Python

A_裙232550246
32分钟前
0
0

47分钟前
3
0
List list = new ArrayList()为何父类引用指向子类对象（多态）

architect刘源源
48分钟前
3
0