LintCode First Bad Version
找出第一个出问题的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的更多相关文章
- Lintcode: First Bad Version 解题报告
First Bad Version http://lintcode.com/en/problem/first-bad-version The code base version is an integ ...
- lintcode :First bad version 第一个错误的代码版本
题目 第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...
- 【Lintcode】074.First Bad Version
题目: The code base version is an integer start from 1 to n. One day, someone committed a bad version ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)
--------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- lintcode刷题笔记(一)
最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...
- [leetcode/lintcode 题解] 微软 面试题:实现 Trie(前缀树)
实现一个 Trie,包含 insert, search, 和 startsWith 这三个方法. 在线评测地址:领扣题库官网 样例 1: 输入: insert(" ...
随机推荐
- XMLHttpRequest 加载进度
XMLHttpRequest 相关资料请移步这里直接查看,我这里就不在赘述: https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpReque ...
- PLS-00221: 'function' 不是过程或尚未定义
直接调用addOrgunitInfoByBatch(r_user_batch.seq_id,'01'); 报错PLS-00221: 'function' 不是过程或尚未定义 原因是在调用函数时 ...
- python成长之路【第二篇】:列表和元组
1.数据结构数据结构是通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构.在Python中,最基本的数据结构是序列(sequence) ...
- iOS核心动画学习整理
最近利用业余时间终于把iOS核心动画高级技巧(https://zsisme.gitbooks.io/ios-/content/chapter1/the-layer-tree.html)看完,对应其中一 ...
- 安装 SciPy 和 scikit-learn 升级pip 及pip基本命令表
安装Scipy和scikit-learn出错,出错记录及当时最终解决办法 问题: 一.使用pip直接安装 直接pip install scipy C:\Users\Plain>pip insta ...
- Linux下使用autoconf 和 automake 编译简单的HelloWorld
使用过开源C/C++项目的同学都知道,标准的编译过程已经变成简单的三部曲:./configure /make/make install,使用起来很方便,不像平时自己写代码,要手写一堆复杂的makefi ...
- python + selenium相关事件和元素定位
女友由于工作上的失误,将公司RDM中的某一字段的2000条数据给删除了.....就算是重新添加字段,但是与其他数据的关联性已经不在了.由于每天的数据修改量大,有关部门不愿意恢复数据库,因此只能一条条的 ...
- Yii 提示Invalid argument supplied for foreach() 等错误
Yii 提示Invalid argument supplied for foreach() 或者 undefined variable: val等错误 只需要在对应的文件中加入error_report ...
- jQuery水平下拉菜单实现
<!DOCTYPE html> <html> <head> <title>jQuery水平下拉菜单实现</title> ...
- DIV设置overflow无效的原因
因为项目需求需要在一个div中添加多个checked 添加的时候使用了 <label><input type="checkbox" value="123 ...