【Lintcode】074.First Bad Version
题目:
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的更多相关文章
- 【lintcode】 二分法总结 I
二分法:通过O(1)的时间,把规模为n的问题变为n/2.T(n) = T(n/2) + O(1) = O(logn). 基本操作:把长度为n的数组,分成前区间和后区间.设置start和end下标.i ...
- 【转】解决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 ...
- 【easy】278. First Bad Version
有一系列产品,从某个开始其后都不合格,给定一个判断是否合格的函数,找出N个产品中第一个不合格的产品. 正确答案: // Forward declaration of isBadVersion API. ...
- 【leetcode】278. First Bad Version
problem 278. First Bad Version solution1:遍历: // Forward declaration of isBadVersion API. bool isBadV ...
- 【问题解决】Project facet Java version 1.7 (或者1.8)is not supported.
在移植eclipse项目时,如果遇到 “Project facet Java version 1.7 is not supported.” 项目中的jdk1.7不支持.说明项目是其他版本jdk编译的, ...
- 【LeetCode】278. First Bad Version 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.c ...
- 【LintCode】转换字符串到整数
问题描述: 实现atoi这个函数,将一个字符串转换为整数.如果没有合法的整数,返回0.如果整数超出了32位整数的范围,返回INT_MAX(2147483647)如果是正整数,或者INT_MIN(-21 ...
- 【LintCode】判断一个字符串是否包含另一个字符串的所有字符
问题描述: 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母. 样例 给出 A = "ABCD" B = "ACD",返 ...
- 【LintCode】链表求和
问题分析: 我们通过遍历两个链表拿到每个位的值,两个值加上前一位进位值(0或者1)模10就是该位的值,除以10就是向高位的进位值(0或者1). 由于两个链表可以不一样长,所以要及时判断,一旦为null ...
随机推荐
- Chrome禁用NPAPI插件(包含 Silverlight、Java 和 Unity)
过去,很多插件都是使用一种称为NPAPI 的旧系统开发的. 现在,仅仅有少量站点在使用NPAPI 插件,由于这些插件有时会给站点带来安全风险. 为了让用户获得更安全.更高速且更稳定的 Chrome 浏 ...
- 安装 r 里的 igraph 报错
转载来源:http://genek.tv/article/40 1186 0 0 安装 r 里的 igraph 报错: foreign-graphml.c: In function ‘igraph_w ...
- CGI模式下的bug
一般情况下$_SERVER['PHP_SELF'] 与 $_SERVER['SCRIPT_NAME'] 没有什么区别,但是如果PHP是以CGI模式运行的话两者就有差异 建议使用$_SERVER[' ...
- Unity3D 与 objective-c 之间数据交互。iOS SDK接口封装Unity3D接口 .-- 转载
Unity 3D 简单工程的创建.与Xcode 导出到iOS 平台请看这 Unity3D 学习 创建简单的按钮.相应事件 Unity C# 代码 using UnityEngine; using Sy ...
- python 基础 1.5 python数据类型(四)--字典常用方法示例
一. 字典 #字典 dict1 = {'name':'lzc','age':'20','sex':'man'} print dict1 print type(dict1) >>> { ...
- ubuntu中设置wireshark抓包
安装wireshark软件后,打开进行抓包的时候会提示权限不足.原因是普通用户没有执行权限,也打不开网络端口捕捉,因为dumpcap需要root权限. 产生这种问题的原因:比如:wireshark在进 ...
- python之学习
------------------------------------------ 基本语句解析 import:导入某些模块或者文件 import random: 导入生成随机数模块 import ...
- Java多线程系列 基础篇03 线程的优先级和守护线程
1. 线程优先级 现代操作系统中基本上使用时间分片的方式调度线程,通过设置线程优先级,使优先级高的线程获得时间片的次数多于优先级低的线程. 在java 线程中,通过一个整形变量prority来控制优先 ...
- <算法导论>高级数据结构--以我的角度看B树(Balanced-Tree)的建增删查
题外话:在博客园看了几篇关于B树的博文确实很有帮助,但是也看到有一些Funny的博文- -比如拿二叉树堂(BinaryTree)而皇之写上B树的帽子. 好了题归正传,B树(Balanced-Tree) ...
- SDUT OJ 2616 简单计算
简单计算 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 某天,XX 给YY 出了一道题,题目是: 给出n 个十进制的数,找出这n ...