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
相关推荐
萧鼎6 分钟前
Python Mahotas 图像处理库:高性能计算机视觉工具
图像处理·python·计算机视觉
未若君雅裁10 分钟前
LeetCode 51 - N皇后问题 详解笔记
java·数据结构·笔记·算法·leetcode·剪枝
破烂pan11 分钟前
lmdeploy.pytorch 新模型支持代码修改
python·深度学习·llm·lmdeploy
麦麦大数据1 小时前
F047 vue3+flask微博舆情推荐可视化问答系统
python·flask·知识图谱·neo4j·推荐算法·舆情分析·舆情监测
MediaTea1 小时前
Python 第三方库:Flask(轻量级 Web 框架)
开发语言·前端·后端·python·flask
Kuo-Teng1 小时前
LeetCode 198: House Robber
java·算法·leetcode·职场和发展·动态规划
java干货1 小时前
Spring Boot 为什么“抛弃”了 spring.factories?
spring boot·python·spring
2501_941111822 小时前
使用Python进行网络设备自动配置
jvm·数据库·python
源码之家2 小时前
基于python租房大数据分析系统 房屋数据分析推荐 scrapy爬虫+可视化大屏 贝壳租房网 计算机毕业设计 推荐系统(源码+文档)✅
大数据·爬虫·python·scrapy·数据分析·推荐算法·租房