Leetcode First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.
You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
假设序列为 PPPPFFFFFF,我们其实是想到找第一个F。所以这是一个典型的binary search寻找第一个>=target的问题。
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version): class Solution(object):
def firstBadVersion(self, n):
"""
:type n: int
:rtype: int
"""
left = 1
right = n while left < right:
mid = (left + right)/2
if isBadVersion(mid):
right = mid
else:
left = mid+1 return left
Leetcode First Bad Version的更多相关文章
- [LeetCode] First Bad Version 第一个坏版本
You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...
- [LeetCode] 165. Compare Version Numbers 比较版本数
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
- 【leetcode】Compare Version Numbers
题目描述: Compare two version numbers version1 and version2. If version1 > version2 return 1, if vers ...
- 【leetcode】Compare Version Numbers(middle)
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- ✡ leetcode 165. Compare Version Numbers 比较两个字符串数字的大小 --------- java
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- Java for LeetCode 165 Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- LeetCode First Bad Version (二分查找)
题意: 有一个bool序列表示对应下标的版本是否出问题(下标从1开始),如果一个版本出了问题,那么其后面全部版本必定出问题.现在给出判断任意版本是否出问题的API,请找到第一个出问题的版本. 思路: ...
- leetcode:Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- Java [Leetcode 165]Compare Version Numbers
题目描述: Compare two version numbers version1 and version2.If version1 > version2 return 1, if versi ...
随机推荐
- UNR #1 题解
A. 争夺圣杯 还是想说一下,这题是原题啊...想做的人可以戳codechef上的MTMXSUM(懒得贴链接了,套了个壳,不过正常人应该都能看得出来) 显然异或输出没什么奇怪的性质... 考虑一个元素 ...
- crontab日常使用梳理
在日常的运维工作中,对crontab定时任务的制定是再寻常不过的了.根据以往的使用经验梳理如下: 基本格式 :* * * * * command分 时 日 月 周 命令解释:第1列表示分钟1-59 每 ...
- iOS崩溃调试的使用和技巧总结
在iOS开发调试过程中以及上线之后,程序经常会出现崩溃的问题.简单的崩溃还好说,复杂的崩溃就需要我们通过解析Crash文件来分析了,解析Crash文件在iOS开发中是比较常见的. 现在网上有很多关于解 ...
- Laterality issue on fMRI image
The laterality issue: different software will interpret fMRI images in different way (mainly refer t ...
- DataReader用法
一.DataReader含义 DataReader相比于DataSet,DataReader是一个抽象类,所以不能用DataReader DR = new DataReader(),来构造函数创建对象 ...
- nginx认证配置
rpm -qa|grep httpd-tools yum install httpd-tools ###这样不仅可以使用ab工具,还可以使用htpasswd工具了 虚拟主机 ->&g ...
- 端口扫描base
#coding:utf8 import os import socket import sys def IsOpen(ip,port): s = socket.socket(socket.AF_INE ...
- 机械大楼电梯控制项目软件 -- github团队组建
目前在Github网站上建立了机械大楼电梯控制项目软件的软件仓库(Repository),提供了软件功能需求说明文档和Automation Studio程序模板.地址为 https://github. ...
- 命令行下 mysql 不是内部或外部命令排查方法
首先确定你没有更改过MySQL的安装目录.如果你进行过改名或者更改了你的路径,那么要在相应的配置文件中更改你的你路径.找到C:\Windows\my.ini文件,更改你配置的文件路径,改成你修改后的路 ...
- Expression Blend4经验分享:制作一个简单的文字按钮样式
首先在Grid里放一个TextBlock,对象时间线窗口的结构树如下 右键点击grid,选择构成控件 会弹出构成控件的对话框,选择你要构成的控件类型,控件名称,控件样式存储位置 这里我们选择butto ...