找出第一个出问题的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. Chrome浏览器快捷键大全(新加了其他一些浏览器的独有)

    官方快捷键文档: https://support.google.com/chrome/answer/157179?hl=zh-Hans&ref_topic=14676   浏览器标签页和窗口快 ...

  2. GITHUB使用简介

    前提:本地开通SSH服务  我是Ubuntu OS,其他OS自行查找,不难目的:利用Github的免费托管服务,创建自己的repo或者fork别人的repo.步骤:·安装客户端  安装如下两个git  ...

  3. javascript guid(uuid)

    http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript function generateU ...

  4. Js 类定义的几种方式

    提起面向对象我们就能想到类,对象,封装,继承,多态.在<javaScript高级程序设计>(人民邮电出版社,曹力.张欣译.英文名字是:Professional JavaScript for ...

  5. Android Fragment是什么

    Fragment是Activity中用户界面的一个行为或者一个部分.你可以在一个单独的Activity上把多个Fragment组合成一个多区域的UI,并且可以在多个Activity中使用.你可以认为F ...

  6. CSS 3 选择器

    css3叫做样式表  对页面的布局,字体,颜色,背景和其他效果做更精确的布置 支持的浏览器有 chrome safari firfox opera 甚至360都开始支持360用的是别的内核 IE10 ...

  7. 详解应对平台高并发的分布式调度框架TBSchedule

    转载: 详解应对平台高并发的分布式调度框架TBSchedule

  8. 常用git命令及问题解决方法

    使用git不久,在这里记录使用git的命令. 1.将本地项目上传git git端 1.[start a project]新建一个项目 example 客户端 1.git init 初始化本地git仓库 ...

  9. phpstormn 中 xdebug 的详细配置2

    配置PHPStorm 图1:首先配置PHP解释器的路径 图2:File>Settings>PHP>Servers,这里要填写服务器端的相关信息,name填localhost,host ...

  10. tomcat通过conf-Catalina-localhost目录发布项目详解 摘自:http://www.cnblogs.com/iyangyuan/archive/2013/09/12/3316444.html

    Tomcat发布项目的方式大致有三种,但小菜认为通过在tomcat的conf/Catalina/localhost目录下添加配置文件,来发布项目,是最佳选择. 因为这样对tomcat的入侵性最小,只需 ...