当前位置:网站首页>sorting and searching 二分查找法
sorting and searching 二分查找法
2022-07-29 15:58:00 【人工智能曾小健】
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
nums1[m:] = nums2
nums1.sort()
class Solution:
def merge(self,nums1:List[int],m:int,nums2:List[int],n:int) ->None
nums1[m:] = nums2
nums1.sort()二分查找法
class Solution:
def firstBadVersion(self, n: int) -> int:
i, j = 1, n
while i <= j:
# 向下取整除法计算中点 m
m = (i + j) // 2
# 若 m 是错误版本,则最后一个正确版本一定在闭区间 [i, m - 1]
if isBadVersion(m): j = m - 1
# 若 m 是正确版本,则首个错误版本一定在闭区间 [m + 1, j]
else: i = m + 1
# i 指向首个错误版本,j 指向最后一个正确版本
return i
class Solution:
def firstBadVersion(self,n:int) -> int:
i,j =1,n
while i<= j:
#向下取整除法计算中点m
m =(i+j)//2
#若m是错误版本,则最后一个正确版本一定在
if isBadVersion(m): j=m-1
else: i =m+1
return iclass Solution:
def firstBadVersion(self,n:int) -> int:
i,j =1,n
while i<=j:
m= (i+j)//2
if isBadVersion(m): j=m-1
else: i=m+1
return i边栏推荐
- 718. 最长重复子数组
- Interviewer: What are the design principles?What is the Lie Substitution Principle?
- 面试突击69:TCP 可靠吗?为什么?
- 一文看懂分布式存储架构
- 【Go语言刷题篇】Go完结篇函数、结构体、接口、错误入门学习
- 使用DataEase开源工具制作一个高质量的数据大屏
- Turbine Aggregation Monitoring
- 溢价20%,瑞萨电子宣布拟以60亿美元收购Dialog
- 旭硝子龟尾工厂3月起将减少30%玻璃基板供应!TCL华星、友达、群创、惠科均受影响
- Steam CMD是什么?Steam CMD怎么用?
猜你喜欢

显微镜LED补光可调光源

蚂蚁三面滑铁卢!遭分布式截胡,靠这些笔记潜修 30 天,挺进京东

图文结合纯c手写内存池

How should small and medium-sized financial enterprises carry out disaster recovery construction?

Compose要是不 `remember`,相关功能就实现不了了吗?

Sentinel热门词汇限流如何实现

SAP ABAP OData 服务诊断工具 /IWFND/ERROR_LOG 的使用方法试读版

重磅来袭!豆瓣评分9.9,万人血书的多线程与高并发v2.0版本

中国大学慕课mooc答题/自动播放脚本(domooc)使用教程

Turbine聚合监控
随机推荐
最新!多交的税可以退,同学,你今天退税了吗?
GBJ2510-ASEMI电机专用25A整流桥GBJ2510
uni-app进阶之Weex/nvu
BUUCTF——MISC(流量分析)
传输层 TCP的连接管理-释放连接四次握手
Qt笔记-利用QAxObject将文件夹内的所有docx转pdf
中国大学慕课mooc答题/自动播放脚本(domooc)使用教程
win10 校验sha256
CAS原理以及ABA问题解决Demo-代码
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
面试官:小伙子你来说说MySQL底层架构设计
蚂蚁三面滑铁卢!遭分布式截胡,靠这些笔记潜修 30 天,挺进京东
[Designers must learn] Lighting skills of Enscape in SketchUp
货比三家 tb1.3
Moving forward steadily without forgetting the original intention, Volvo's sense of security comes from the public's recognition
uni-app深入学习之模板运用
稳步向前不忘初心,沃尔沃的安全感来自公众的认可
虚拟远程桌面
tcp的四次挥手(为什么三次握手和四次挥手)
Property (Property Animation Animation), the basic use of Butterknife butter knife