python-leetcode-搜索二维矩阵

74. 搜索二维矩阵 - 力扣(LeetCode)


python 复制代码
class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        if not matrix or not matrix[0]:
            return False
        
        m, n = len(matrix), len(matrix[0])
        left, right = 0, m * n - 1
        
        while left <= right:
            mid = left + (right - left) // 2
            row = mid // n
            col = mid % n
            
            if matrix[row][col] == target:
                return True
            elif matrix[row][col] < target:
                left = mid + 1
            else:
                right = mid - 1
        
        return False
相关推荐
18538162800余+18 小时前
数字人分身 + 矩阵系统聚合的源码搭建与定制开发
线性代数·矩阵
Swift社区18 小时前
LeetCode 378 - 有序矩阵中第 K 小的元素
算法·leetcode·矩阵
阿拉丁的梦18 小时前
【maxscript】矩阵对齐-武器残影
python·3dsmax
mortimer18 小时前
Python 异常处理进阶:从 `traceback` 细节到稳健的多语言处理器
python
墨染点香18 小时前
LeetCode 刷题【73. 矩阵置零】
算法·leetcode·矩阵
semantist@语校18 小时前
第十九篇|东京世界日本语学校的结构数据建模:制度函数、能力矩阵与升学图谱
数据库·人工智能·线性代数·矩阵·prompt·github·数据集
林木辛18 小时前
LeetCode热题 438.找到字符中所有字母异位词 (滑动窗口)
算法·leetcode
和鲸社区18 小时前
四大经典案例,入门AI算法应用,含分类、回归与特征工程|2025人工智能实训季初阶赛
人工智能·python·深度学习·算法·机器学习·分类·回归
dragoooon3418 小时前
[优选算法专题二——NO.16最小覆盖子串]
c++·算法·leetcode·学习方法