题目:

The code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the following versions are all failed in the unit tests. Find the first bad version.

You can call isBadVersion to help you determine which version is the first bad one. The details interface can be found in the code's annotation part.

you can use SVNRepo::isBadVersion(k) to judge whether the kth code version is bad or not.

题解:

  注意:SVNRepo::isBadVersion(k)不能写成SVNRepo.isBadVersion(k), Lintcode要求这么写,后者编译错误。

class Solution {
public:
/**
* @param n: An integers.
* @return: An integer which is the first bad version.
*/
int findFirstBadVersion(int n) {
int start = , end = n;
while (start + < end) {
int mid = start + (end - start) / ;
if (SVNRepo::isBadVersion(mid)) {
end = mid;
} else {
start = mid;
}
} if (SVNRepo::isBadVersion(start)) {
return start;
} return end;
}
};

【Lintcode】074.First Bad Version的更多相关文章

  1. 【lintcode】 二分法总结 I

     二分法:通过O(1)的时间,把规模为n的问题变为n/2.T(n) = T(n/2) + O(1) = O(logn). 基本操作:把长度为n的数组,分成前区间和后区间.设置start和end下标.i ...

  2. 【转】解决Cannot change version of project facet Dynamic web module to 2.5

    http://blog.csdn.net/steveguoshao/article/details/38414145 我们用Eclipse创建Maven结构的web项目的时候选择了Artifact I ...

  3. 【easy】278. First Bad Version

    有一系列产品,从某个开始其后都不合格,给定一个判断是否合格的函数,找出N个产品中第一个不合格的产品. 正确答案: // Forward declaration of isBadVersion API. ...

  4. 【leetcode】278. First Bad Version

    problem 278. First Bad Version solution1:遍历: // Forward declaration of isBadVersion API. bool isBadV ...

  5. 【问题解决】Project facet Java version 1.7 (或者1.8)is not supported.

    在移植eclipse项目时,如果遇到 “Project facet Java version 1.7 is not supported.” 项目中的jdk1.7不支持.说明项目是其他版本jdk编译的, ...

  6. 【LeetCode】278. First Bad Version 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.c ...

  7. 【LintCode】转换字符串到整数

    问题描述: 实现atoi这个函数,将一个字符串转换为整数.如果没有合法的整数,返回0.如果整数超出了32位整数的范围,返回INT_MAX(2147483647)如果是正整数,或者INT_MIN(-21 ...

  8. 【LintCode】判断一个字符串是否包含另一个字符串的所有字符

    问题描述: 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母. 样例 给出 A = "ABCD" B = "ACD",返 ...

  9. 【LintCode】链表求和

    问题分析: 我们通过遍历两个链表拿到每个位的值,两个值加上前一位进位值(0或者1)模10就是该位的值,除以10就是向高位的进位值(0或者1). 由于两个链表可以不一样长,所以要及时判断,一旦为null ...

随机推荐

  1. Error executing DDL via JDBC Statement

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 启动hibernate测试案例时报错如下: org.hibernate.tool.schema.spi.CommandAcceptan ...

  2. 【甘道夫】Ubuntu14 server + Hadoop2.2.0环境下Sqoop1.99.3部署记录

    第一步.下载.解压.配置环境变量: 官网下载sqoop1.99.3 http://mirrors.cnnic.cn/apache/sqoop/1.99.3/ 将sqoop解压到目标文件夹,我的是 /h ...

  3. kvm&vnc 简单安装shell脚本

    #!/bin/bash # created on 2014/7/15 #author : derrick.jiang (Email: derrick.jiang.maichuang.net) echo ...

  4. ios何时使用self.

     本文转载至  http://blog.csdn.net/lvxiangan/article/details/27204265   何时使用self.在网上搜索或者论坛里的回复大多都是简简单单的说这与 ...

  5. Cocos2d-js官方完整项目教程翻译:六、添加Chipmunk物理引擎在我们的游戏世界里

    添加Chipmunk物理引擎在我们的游戏世界里         一.简介                   cocos2d JS能给我们力量来创造令人印象深刻的游戏世界.但缺乏某种现实.       ...

  6. centos7 执行一个数据库脚本创建项目中的数据库

    [root@localhost ~]# su postgres 切换用户 bash-4.2$ psql could not change directory to "/root": ...

  7. cocos2d-x中对象的位置,旋转,缩放

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/cuit/article/details/26729633 分为两种: 缓动.IntervalActi ...

  8. 关于SAP S4 HANA 的13个问题

    SAP S/4HANA的路线图是怎样的?价格是多少?下一步还将添加哪些新模块?莫不闻专业SAP问答平台结合SAP HANA及SAP HANA应用商务套件开发全球负责人Uwe Grigoleit帮大家整 ...

  9. Java for LeetCode 103 Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  10. SpringBoot学习笔记(11):使用WebSocket构建交互式Web应用程序

    SpringBoot学习笔记(11):使用WebSocket构建交互式Web应用程序 快速开始 本指南将引导您完成创建“hello world”应用程序的过程,该应用程序在浏览器和服务器之间来回发送消 ...