【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)
相关推荐
智算菩萨2 分钟前
【Tkinter】15 样式与主题深度解析:ttk 主题系统、Style 对象与跨平台样式管理实战
开发语言·python·ui·ai编程·tkinter
子非鱼@Itfuture17 分钟前
`<T> T execute(...)` 泛型方法 VS `TaskExecutor<T>` 泛型接口对比分析
java·开发语言
样例过了就是过了20 分钟前
LeetCode热题100 柱状图中最大的矩形
数据结构·c++·算法·leetcode
weixin_4193497921 分钟前
Python 项目中生成 requirements.txt 文件
开发语言·python
林恒smileZAZ25 分钟前
前端大屏适配方案:rem、vw/vh、scale 到底选哪个?
开发语言·前端·css·css3
wsoz27 分钟前
Leetcode哈希-day1
算法·leetcode·哈希算法
阿Y加油吧30 分钟前
LeetCode 二叉搜索树双神题通关!有序数组转平衡 BST + 验证 BST,小白递归一把梭
java·算法·leetcode
第一程序员34 分钟前
Python与区块链:非科班转码者的指南
python·github
BlockChain88835 分钟前
区块链的组件:从数据结构到去中心化共识
数据结构·去中心化·区块链
liu****43 分钟前
LangChain-AI应用开发框架(六)
人工智能·python·langchain·大模型应用·本地部署大模型