【搜索二维矩阵】python刷题记录

R4-二分查找专题

直接二维变一维,然后二分查找就可以了

python 复制代码
class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        nums=[i for row in matrix for i in row]
        def binfind(the,target):
            low,high=0,len(the)-1
            while low<=high:
                  mid=(low+high)//2
                  if the[mid]==target:
                       return True
                  elif the[mid]>target:
                       high=mid-1
                  else:
                       low=mid+1
            return False
        return binfind(nums,target)
相关推荐
Stanford_110610 小时前
如何利用Python进行数据分析与可视化的具体操作指南
开发语言·c++·python·微信小程序·微信公众平台·twitter·微信开放平台
2501_9159090611 小时前
HTML5 与 HTTPS,页面能力、必要性、常见问题与实战排查
前端·ios·小程序·https·uni-app·iphone·html5
Vallelonga11 小时前
Rust 中的数组和数组切片引用
开发语言·rust
Kiri霧11 小时前
Rust模式匹配详解
开发语言·windows·rust
white-persist12 小时前
Python实例方法与Python类的构造方法全解析
开发语言·前端·python·原型模式
千里马-horse12 小时前
Async++ 源码分析8--partitioner.h
开发语言·c++·async++·partitioner
Java 码农12 小时前
Centos7 maven 安装
java·python·centos·maven
格林威12 小时前
常规线扫描镜头有哪些类型?能做什么?
人工智能·深度学习·数码相机·算法·计算机视觉·视觉检测·工业镜头
新中地GIS开发老师12 小时前
Cesium 军事标绘入门:用 Cesium-Plot-JS 快速实现标绘功能
前端·javascript·arcgis·cesium·gis开发·地理信息科学
Superxpang13 小时前
前端性能优化
前端·javascript·vue.js·性能优化