找出第一个出问题的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. ios下移除原生样式

    之前遇到过这个问题,今天无意中在网上看见博文 记录一下. 设置这个就好: -webkit-appearance : none ;

  2. HTTP协议的头信息详解

    转载地址:http://blog.csdn.net/guoguo1980/article/details/2649658 HTTP(HyperTextTransferProtocol)是超文本传输协议 ...

  3. Servlet 实现上传文件以及同时,写入xml格式文件和上传

    package com.isoftstone.eply.servlet; import java.io.BufferedReader; import java.io.BufferedWriter; i ...

  4. bootloader(转)

    本文详细地介绍了基于嵌入式系统中的 OS 启动加载程序 ―― Boot Loader 的概念.软件设计的主要任务以及结构框架等内容. 1. 引言在专用的嵌入式板子运行 GNU/Linux 系统已经变得 ...

  5. C++ do{...}while(0)的好处

    在开源软件里面经常可以看到这样的写法. #define X(a) do { f1(a); f2(a); } while(0) 1. 主要作用是放在宏定义里面,避免宏带来的语法问题. 比如 #defin ...

  6. Android复习指南

    基础无外乎几部分:语言(C/C++或java),操作系统,TCP/IP,数据结构与算法,再加上你所熟悉的领域.这里面其实有很多东西,各大面试宝典都有列举. 在这只列举了Android客户端所需要的和我 ...

  7. 转:[置顶] 从头到尾彻底理解KMP(2014年8月22日版)

    [置顶] 从头到尾彻底理解KMP(2014年8月22日版)

  8. linux配置ssh互信

    公钥认证的基本思想: 对信息的加密和解密采用不同的key,这对key分别称作private key和public key,其中,public key存放在欲登录的服务器上,而private key为特 ...

  9. Android 控件知识点

    一.引入布局 在xml文件中引入另一个布局 <include layout="@layout/XXX" /> 个人理解就是在父布局的某个位置在嵌套一个布局. 二.自定义 ...

  10. easyui tree 折叠节点

    <ul id="jihuidian" class="easyui-tree" data-options="onBeforeLoad:functi ...