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号14 小时前
力扣热题100道之78子集
算法·leetcode·职场和发展
布茹 ei ai14 小时前
地表沉降监测分析系统(vue3前端+python后端+fastapi+网页部署)(开源分享)
前端·python·fastapi
闲人编程14 小时前
API限流、鉴权与监控
分布式·python·wpf·限流·集群·令牌·codecapsule
封奚泽优14 小时前
Deep-Live-Cam(调试和求助)
git·python·ffmpeg·pip·cuda
萤火虫的夏天25114 小时前
虚拟环境安装tensorflow使用GPU加速,显卡:1650ti
人工智能·python·tensorflow
视频技术分享14 小时前
内网视频会议升级之选:云屋,30 分钟部署替代腾讯会议
python·腾讯会议
dragoooon3414 小时前
[优选算法专题十一.字符串 ——NO.60~63 最长公共前缀、5最长回文子串、 二进制求和 、字符串相乘]
算法·leetcode·动态规划
CHANG_THE_WORLD14 小时前
Python元组(Tuple)详解
开发语言·python
SadSunset15 小时前
(15)动态SQL中的if,foreach和一些其他的常用标签
数据库·python·sql
CoderYanger15 小时前
C.滑动窗口——2762. 不间断子数组
java·开发语言·数据结构·算法·leetcode·1024程序员节