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
相关推荐
Frostnova丶4 小时前
LeetCode 190.颠倒二进制位
java·算法·leetcode
CeshirenTester6 小时前
9B 上端侧:多模态实时对话,难点其实在“流”
开发语言·人工智能·python·prompt·测试用例
Starry_hello world6 小时前
Python (2)
python
ID_180079054736 小时前
Python爬取京东商品库存数据与价格监控
jvm·python·oracle
json{shen:"jing"}6 小时前
字符串中的第一个唯一字符
算法·leetcode·职场和发展
追随者永远是胜利者6 小时前
(LeetCode-Hot100)15. 三数之和
java·算法·leetcode·职场和发展·go
-To be number.wan7 小时前
Python数据分析:时间序列数据分析
开发语言·python·数据分析
程序员酥皮蛋7 小时前
hot 100 第二十七题 27.合并两个有序链表
数据结构·leetcode·链表
Faker66363aaa7 小时前
YOLO13-C3K2-AdditiveBlock:水果质量智能检测系统_3
python
2401_828890648 小时前
实现扩散模型 Stable Diffusion - MNIST 数据集
人工智能·python·深度学习·stable diffusion