【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)
相关推荐
tryCbest15 小时前
Python 爬虫从入门到实战(二):进阶篇——反爬对抗、并发与动态页面
开发语言·爬虫·python
VIP_CQCRE15 小时前
GPT Image 2.6 动态表情交付别只发预览:GIF 文件校验、哈希清单与下载排错
图像处理·人工智能·python·gif
2601_9679873715 小时前
使用 NumPy 和 Python 实现梯度下降
python·机器学习·线性回归·numpy·梯度下降
张祥64228890415 小时前
RTKLIB 源码解析:方差计算与高度角定权模型深度剖析
算法
BD_Marathon15 小时前
Jupyter魔法命令
ide·python·jupyter
S_WEAN15 小时前
【C++】STL - Priority_queue的使用及模拟实现与仿函数
开发语言·c++
词却15 小时前
Python 正则表达式实战:使用 re 模块提取符合条件的字符串
python·正则表达式
电科_银尘16 小时前
【大模型算法与工程 37】语言模型强化学习基础:策略、奖励与优势
人工智能·算法·语言模型
2401_8582861116 小时前
LKDS8.Linux内核的双向链表代码解析(8) 拼接链表、获取链表首/尾元素的宏、list_for_each系列的安全版本的宏
linux·链表
星落梦生16 小时前
Tlias前端案例涉及知识点 (14)
开发语言·前端·javascript