• Total Accepted: 58296
• Total Submissions: 248778
• Difficulty: Easy

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.

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

1、注意返回条件begin 和 end相等，和一开始调用findRange的条件。

3、mid = （low+high）先发生了数据溢出，应该将其改为mid = low+(high-low)/2      //不知道这么解释对不对。

public class Solution extends VersionControl {
if(n == 1||n == 0) return n;
int res = findRange(1,n);
return res;
}

public int findRange(int begin,int end){
if(begin == end) return begin;

int mid = begin + (end - begin)/2;

if(checkRes)
return findRange(begin,mid);
else
return findRange(mid+1,end);
}
}

• 本文已收录于以下专栏：

You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...
• booirror
• 2015年09月09日 09:44
• 4816

## leetcode 278: First Bad Version

First Bad Version Total Accepted: 1415 Total Submissions: 5826 You are a product manag...
• xudli
• 2015年09月08日 08:49
• 4310

• pistolove
• 2015年11月08日 16:22
• 1500

## 278. First Bad Version (二分，java)

278. First Bad Version DescriptionSubmissionsSolutions Total Accepted: 90906Total Submi...
• CriminalCode
• 2017年04月03日 10:07
• 163

## 278. First Bad Version (查找第一个错误版本)

You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...
• xiangwanpeng
• 2016年10月28日 10:32
• 208

## leetcode 278. First Bad Version-第一个坏版本|二分查找

• happyaaaaaaaaaaa
• 2016年05月19日 21:49
• 271

## leetcode 278. First Bad Version 二分查找

You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...
• JackZhang_123
• 2017年09月27日 10:13
• 51

## 278. First Bad Version LeetCode

• youthinkwu
• 2016年02月13日 16:00
• 101

278. First Bad Version You are a product manager and currently leading a team to develop a new pr...
• dumpling5232
• 2016年08月24日 16:10
• 71