mycode  96.42

# 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
"""
l , r = 1 , n
while l < r:
mid = (l + r)//2
if isBadVersion(mid):
r = mid
else:
l = mid + 1
return l

参考

# 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
""" l, r = 1, n while l <= r:
mid = (l + r) // 2
if isBadVersion(mid):
r = mid - 1
else:
l = mid + 1
return l

leetcode-easy-sorting and searching- 278 First Bad Version的更多相关文章

  1. Leetcode easy

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  2. leetcode 704. Binary Search 、35. Search Insert Position 、278. First Bad Version

    704. Binary Search 1.使用start+1 < end,这样保证最后剩两个数 2.mid = start + (end - start)/2,这样避免接近max-int导致的溢 ...

  3. 【leetcode】278. First Bad Version

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

  4. 278. First Bad Version - LeetCode

    Question 278. First Bad Version Solution 题目大意:产品有5个版本1,2,3,4,5其中下一个版本依赖上一个版本,即版本4是坏的,5也就是坏的,现在要求哪个版本 ...

  5. 20162314 Experiment 3 - Sorting and Searching

    Experiment report of Besti course:<Program Design & Data Structures> Class: 1623 Student N ...

  6. Algorithm in Practice - Sorting and Searching

    Algorithm in Practice Author: Zhong-Liang Xiang Date: Aug. 1st, 2017 不完整, 部分排序和查询算法, 需添加. Prerequisi ...

  7. leetcode easy problem set

     *勿以浮沙筑高台* 持续更新........     题目网址:https://leetcode.com/problemset/all/?difficulty=Easy 1. Two Sum [4m ...

  8. 决战Leetcode: easy part(51-96)

    本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! em ...

  9. 决战Leetcode: easy part(1-50)

    本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! em ...

  10. Chp11: Sorting and Searching

    Common Sorting Algo: Bubble Sort: Runime: O(n2) average and worst case. Memory: O(1). void BubbleSor ...

随机推荐

  1. Webpack loaderUtils.parseQuery()

    https://blog.256pages.com/webpack-loaderutils-parsequery/

  2. Express multer 文件上传

    npm multer 文件上传 Express app 范本就不写了,仅记录一下上传部分的代码. const fs = require('fs'); const express = require(' ...

  3. 封装H5ToApp方法

    方法一: 新建个 Android studio 项目,用 webview 指定访问你的页面 方法二: 使用工具 cordova  附上地址:http://cordova.axuer.com/docs/ ...

  4. JQuery——关于CDN(内容分发网络)

    替代方案 如果您不希望下载并存放 jQuery,那么也可以通过 CDN(内容分发网络) 引用它. Staticfile CDN.百度.又拍云.新浪.谷歌和微软的服务器都存有 jQuery . 如果你的 ...

  5. vue路由公用

    大体思路,一个页面,多个按钮,点击按钮后都跳转到一个路由:通过父亲传的值是什么,来决定跳那个路由:ajax数据也是通过判断来决定拉那个数据 路由: export default { routes: [ ...

  6. 2.bat文件的基本用途

    一.调用可执行的jar文件. 详见:https://www.cnblogs.com/lukelook/p/8683352.html

  7. 第一篇.1、python基础之核心风格

    一.语句和语法 #:注释 \:转译回车,继续上一行,在一行语句较长的情况下可以使用其来切分成多行,因其可读性差所以不建议使用 ::将两个语句连接到一行,可读性差,不建议使用 ::将代码的头和体分开 语 ...

  8. Type Trait 和 Type Utility

    所谓Type trait,提供了一种用来处理type 属性的办法,它是个template,可在编译期根据一个或多个template实参(通常也是type)产出一个type或者value. templa ...

  9. Python名称空间与作用域

    什么是名称空间? 比如下图的长方形代表内存,在这个内存里我要设置一个变量100,那么这个变量得有个门牌号,就叫他a吧,但其实变量不是这么存储的,他其实的存储方式是这样的,他会有一个名称空间,这个名称空 ...

  10. kubernetes创建资源的两种方式

    一.创建方式分类: 命令 vs 配置文件 Kubernetes 支持两种方式创建资源: 1.用 kubectl 命令行的方式直接创建,比如: kubectl run httpd-app --image ...