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. nginx入门,安装

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在 ...

  2. java 周期时期计算

    package org.apple.date; import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut ...

  3. docker下进去mysql 编写语句

    设置密码可使用 docker exec -it mysql01 bash        --mysql01:数据库名字 mysql -u root -p ALTER USER 'root'@'%' I ...

  4. adb进阶知识,如何过滤只查看某一个app的日志

    前面大概学习了adb基础,但是adb的存在,在测试人员中究竟有什么必要,以及看log时,那么多的log,让我们看个屁啊,所以这一次,我决定一定要把adb这件事情搞清楚.   1.先来看最感兴趣的adb ...

  5. 月薪 30K Java 程序员,需要掌握哪些技术?

    转载自:Java3y 1-5年的Java程序员,薪资区间大致是在15-25K左右,那有没有可能提前达到30K的薪资呢?有人说这只能是大企业或者互联网企业工程师才能拿到.也许是的,小公司或者非互联网企业 ...

  6. c++实现服务器和多个客户端的实时群聊通信

    我们通过TCP/IP来实现多人聊天室,如果租一个服务器我们就可以实现全网的多人聊天室(不懂tcp/ip的点进来https://www.cnblogs.com/yskn/p/9335608.html)! ...

  7. Python测试开发必知必会-PEP

    互联网发展了许多年,不仅颠覆了很多行业,还让很多职位有了更多的用武之地.产品发布迭代速度不断加快,让测试开发这个岗位简直火得不要不要的. Python语言,作为一种更接近人来自然语言的开发语言,以简洁 ...

  8. 背包 || NOIP 2018 D1 T2 || Luogu P5020 货币系统

    题面:P5020 货币系统 题解: 显然要求的货币系统是当前货币系统的子集时答案会更优,于是考虑从当前货币系统中删数 一个大数如果能被其他小数表示出来,它就可以去掉 把数据排个序去个重,然后直接背包 ...

  9. Gym - 101173H Hangar Hurdles (kruskal重构树/最小生成树+LCA)

    题目大意:给出一个n*n的矩阵,有一些点是障碍,给出Q组询问,每组询问求两点间能通过的最大正方形宽度. 首先需要求出以每个点(i,j)为中心的最大正方形宽度mxl[i][j],可以用二维前缀和+二分或 ...

  10. Fiddler debug 拦截文件

    前言 前端每次本地调试的需要重新build文件,而且如果当前文件是在另外一个项目中使用,则还需要拷贝到另外一个项目下面.这个工作很耗时.如果使用替换包,可以节省很多时间,也便于开发. 解决方案 用Fi ...