当前位置:网站首页>[binary search - simple] 278 First wrong version
[binary search - simple] 278 First wrong version
2022-04-21 15:11:00 【Caicai 2022】
【 subject 】
Example 1:
Input :n = 5, bad = 4
Output :4
explain :
call isBadVersion(3) -> false
call isBadVersion(5) -> true
call isBadVersion(4) -> true
therefore ,4 It's the first wrong version .
Example 2:
Input :n = 1, bad = 1
Output :1
Tips :
1 <= bad <= n <= 231 - 1
【 Code 】
Execution time :36 ms, In all Python3 Defeated in submission 61.83% Users of
Memory consumption :14.9 MB, In all Python3 Defeated in submission 27.64% Users of
Pass the test case :22 / 22
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return an integer
# def isBadVersion(version):
class Solution:
def firstBadVersion(self, n):
""" :type n: int :rtype: int """
left,right=1,n
while left<right:
mid=left+(right-left)//2
if isBadVersion(mid)==True:
right=mid
else:
left=mid+1
return left
版权声明
本文为[Caicai 2022]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211507332968.html
边栏推荐
- 【C语言进阶】自定义类型:结构体,位段,枚举,联合
- C# 11 对 ref 和 struct 的改进
- Dry goods | application packaging or test team?
- pytorch图像分类篇:pytorch官方demo实现一个分类器(LeNet)
- 阿里超大规模 Flink 集群运维体系介绍
- Lightgbm topic 3: implementation of stringindexer and pipeline functions in pyspark
- 架构实战毕业总结
- C language preprocessing problem
- Qt网络与通信(TCP聊天室)
- lightGBM专题5:pyspark表数据处理之数据合并
猜你喜欢
随机推荐
武汉科技大学C语言上机实验题(第一第二第三部分)
【云驻共创】华为云数据库-基础知识
Detailed explanation of spark SQL underlying execution process
scala安装及环境配置
SAP ui5 application development tutorial 70 - how to trigger page route jump using button control
阿里云云效研发协同服务相关协议条款 |云效
Special test 04 · differential calculus of multivariate functions [Li Yanfang's whole class]
干货 | 环境问题还是测试的老大难?两个步骤轻松搞定
【C语言】C语言标准库大梳理(超全)
如何在Nodejs项目中调用uniCloud云存储进行上传文件
May day financial products have no income?
Excel小技巧-VLOOKUP自动匹配
Beautiful solution for initialization of golang Gorm framework
C language preprocessing problem
Would like to ask how to find the software registration code from the database
Insect 1602
最佳实践 | 疫情之下,了解 eolink 如何助力远程办公!
MYSQL 第1章 数据库简介
干货 | 移动端App自动化之App控件定位
Shang Silicon Valley smart campus - 6. Realization of administrator function









