找出第一个出问题的version。

/**
* public class SVNRepo {
* public static boolean isBadVersion(int k);
* }
* you can use SVNRepo.isBadVersion(k) to judge whether
* the kth code version is bad or not.
*/
class Solution {
/**
* @param n: An integers.
* @return: An integer which is the first bad version.
*/
public int findFirstBadVersion(int n) {
if(n <= 0) return -1; int left = 1; int right = n;
while(left + 1 < right){
int mid = (left + right) / 2;
if(SVNRepo.isBadVersion(mid) == true){
right = mid;
}
else{
left = mid;
}
}
if(SVNRepo.isBadVersion(left)){
return left;
}
else if(SVNRepo.isBadVersion(right)){
return right;
}
else return -1;
}
}

LintCode First Bad Version的更多相关文章

  1. Lintcode: First Bad Version 解题报告

    First Bad Version http://lintcode.com/en/problem/first-bad-version The code base version is an integ ...

  2. lintcode :First bad version 第一个错误的代码版本

    题目 第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...

  3. 【Lintcode】074.First Bad Version

    题目: The code base version is an integer start from 1 to n. One day, someone committed a bad version ...

  4. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  5. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

  6. leetcode & lintcode for bug-free

    刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...

  7. leetcode & lintcode 题解

    刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...

  8. lintcode刷题笔记(一)

    最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...

  9. [leetcode/lintcode 题解] 微软 面试题:实现 Trie(前缀树)

    实现一个 Trie,包含 ​insert​, ​search​, 和 ​startsWith​ 这三个方法.   在线评测地址:领扣题库官网     样例 1: 输入:    insert(" ...

随机推荐

  1. UI设计的分类

    软件UI设计(界面设计包括硬件界面设计和软件界面设计,我们这里探讨的是软件界面设计)包括用户研究.交互设计.与界面设计三部分.   1,用户研究 我们再产品开发的前期,通过调查研究,了解用户的工作性质 ...

  2. (原创)LAMP搭建之二:apache配置文件详解(中英文对照版)

    LAMP搭建之二:apache配置文件详解(中英文对照版) # This is the main Apache server configuration file. It contains the # ...

  3. python成长之路【第七篇】:面向对象

    概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向对象三大特性 面向 ...

  4. 分部类(partial)

    一般来说,一个类.结构或接口位于一个源文件中,但某些情况,比如大型项目.特殊部署时,可能需要把一个类.结构或接口放在几个文件中来处理.等到编译时,自动把它们合起来,这就得应用 C# 分部类了. C# ...

  5. Running With xpi

    d File file = new File("firebug-1.8.1.xpi"); FirefoxProfile firefoxProfile = new FirefoxPr ...

  6. linux 查看所有用户

    cat /etc/passwd | cut -f -d:

  7. ios基础篇(二十)—— UIBezierPath绘制

    UIBezierPath类可以创建基于矢量的路径,可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状. 一.UIBezierPath使用: 1.创建path: 2.添加路径到path ...

  8. BZOJ2095 [Poi2010]Bridges

    首先二分答案...然后这张图变成了有一些有向边,有一些无向边 然后就是混合图欧拉回路的判断 我们知道如果是有向图,它存在欧拉回路的等价条件是所有点的出度等于入度 对于混合图...先不管有向边,把无向边 ...

  9. tslib1.4与Qt4.8.6的交叉编译与移植

    最近开始正式接触QT开发,网上看了些移植教程都写的有点乱,博客园的emouse思·睿有一篇写的很好的文章,下面是文章的链接 http://www.cnblogs.com/emouse/archive/ ...

  10. iOS开发UI篇—UITableviewcell的性能优化和缓存机制

    iOS开发UI篇—UITableviewcell的性能问题 一.UITableviewcell的一些介绍 UITableView的每一行都是一个UITableViewCell,通过dataSource ...