240. 搜索二维矩阵 II


思路

遍历每一行,将当前行的数存放至哈希表中(in的时间复杂度O(1)),查询target是否存在当前行中,是直接返回

遍历结束都找不到target,则说明target不存在

python 复制代码
class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """
        for i in range(len(matrix)):
            s = set(matrix[i])
            if target in s:
                return True

        return False
相关推荐
deephub13 小时前
从检索到回答:RAG 流水线中三个被忽视的故障点
人工智能·python·大语言模型·向量检索·rag
yiruwanlu13 小时前
乡村文旅设计师推荐:建筑设计能力筛选要点解析
python·ui
站大爷IP13 小时前
Python 操作 Word 页眉页脚完整指南
python
SomeB1oody13 小时前
【Python深度学习】2.1. 卷积神经网络(CNN)模型理论(基础):卷积运算、池化、ReLU函数
开发语言·人工智能·python·深度学习·机器学习·cnn
_日拱一卒14 小时前
LeetCode:240搜索二维矩阵Ⅱ
数据结构·线性代数·leetcode·矩阵
WolfGang00732114 小时前
代码随想录算法训练营 Day33 | 动态规划 part06
算法·leetcode·动态规划
solicitous14 小时前
python数据抓取
python
米粒114 小时前
力扣算法刷题 Day 41(买卖股票)
算法·leetcode·职场和发展
HaiXCoder14 小时前
Kotlin vs Python 知识点对照表
python
I疯子14 小时前
2026-04-13 打卡第 6 天
开发语言·python