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

R6-二分查找篇

印象题,直接把它转成一维来处理。

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)
相关推荐
共享家95273 小时前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
疯狂的喵3 小时前
C++编译期多态实现
开发语言·c++·算法
scx201310043 小时前
20260129LCA总结
算法·深度优先·图论
2301_765703143 小时前
C++中的协程编程
开发语言·c++·算法
m0_748708053 小时前
实时数据压缩库
开发语言·c++·算法
小魏每天都学习4 小时前
【算法——c/c++]
c语言·c++·算法
Hgfdsaqwr4 小时前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
lly2024064 小时前
jQuery Mobile 表格
开发语言
一晌小贪欢4 小时前
Python 测试利器:使用 pytest 高效编写和管理单元测试
python·单元测试·pytest·python3·python测试
小文数模4 小时前
2026年美赛数学建模C题完整参考论文(含模型和代码)
python·数学建模·matlab