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
相关推荐
liliangcsdn13 小时前
如何在jupyter-lab显示http链接的图片
python·jupyter
lzjava202414 小时前
Python中的模块和包
linux·开发语言·python
2501_9216494914 小时前
日本股票 API 对接,接入东京证券交易所(TSE)实现 K 线 MACD 指标
大数据·人工智能·python·websocket·金融
笙枫14 小时前
Langchain开发过程中的注意事项
python·ai·langchain
智算菩萨14 小时前
【Python基础】字典(Dictionary):AI的“键值对”信息存储的基石
前端·人工智能·python
追光天使14 小时前
元组、列表、字符串、字典定义及切割
开发语言·python
小白学大数据14 小时前
拉勾网 Ajax 动态加载数据的 Python 爬虫解析
爬虫·python·ajax
2401_8414956414 小时前
【LeetCode刷题】爬楼梯
数据结构·python·算法·leetcode·动态规划·滑动窗口·斐波那契数列
_爱明14 小时前
查看模型参数量
人工智能·pytorch·python
m0_6356474814 小时前
pyqt5打包报错:qt.qpa.plugin: Could not load the Qt platform plugin “windows“
开发语言·windows·python·qt·pyqt