【搜索二维矩阵】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)
相关推荐
you鬰5 分钟前
datawhale--llm-algo-leetcode5️⃣
python·datawhale
七牛开发者17 分钟前
Coding Agent 如何跑稳长任务?从上下文管理到运行时状态
前端·javascript·后端
老洋葱Mr_Onion17 分钟前
【C++】CSP-J初赛模拟卷七错题整理(作者自用)
c++·算法·深度优先
λqaq725 分钟前
MySQL 数据库基础(2)约束、用户权限、远程连接、外键与 TCP/UDP 理解
linux·数据库·python·tcp/ip·mysql
人工干智能28 分钟前
科普:pandas 时间偏移别名:ts.resample(“5Min“).sum()
python·pandas
半个落月29 分钟前
从 CSR 到 Server Component:吃透 Next.js 16 App Router 路由、布局与 SEO
前端·next.js
Nil20831 分钟前
leetcode 114二叉树展开为链表
leetcode·链表·深度优先
七牛开发者35 分钟前
拆解 DeepSeek Harness:Profile 与 Bundle 如何装配运行时
前端·javascript·后端
开源量化GO37 分钟前
最新AI辅助量化表达:先理清规则,再按需求选工具
人工智能·python
土星云SaturnCloud40 分钟前
Real-ESRGAN超分辨率算法原理与边缘侧部署实践
服务器·算法·ai·边缘计算·real-esrgan