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
相关推荐
2601_962299882 分钟前
Linux下运行Python脚本
linux·python·ubuntu·脚本·命令
IT毕设实战小研2 分钟前
基于大数据的DAX40成分股金融新闻情感趋势可视化分析
android·大数据·python·考研·金融·课程设计
三十岁老牛再出发7 分钟前
8月27日总结
python·pandas
砚底藏山河8 分钟前
【量化纯GET实战 #21】用 pandas 做分析:把接口数据变成 DataFrame
java·python·金融·maven·pandas
圣保罗的大教堂11 分钟前
leetcode 3903. 最小稳定下标 I 简单
leetcode
Carl_奕然23 分钟前
【智能体】Agent的四种设计模式之:React(2026最新版)
javascript·人工智能·python·react.js·设计模式·语言模型
岁月宁静25 分钟前
四、《从零手撸 Agent》 — 流式输出:接住 AI “一个字一个字” 想出来的过程
python·agent
是吕先森28 分钟前
【python】selenium实现web自动化测试
前端·python·selenium
卷无止境36 分钟前
从脚本到程序:Windows平台上的Python打包全景图
后端·python
my059236 分钟前
市场学习,不止看资讯,数据查阅与思维练习同样重要
python·学习