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
相关推荐
奇牙7 分钟前
DeepSeek V4 Agent 开发实战:用 deepseek-v4-pro 搭建多步骤工作流(2026 完整代码)
python
斯维赤9 分钟前
Python学习超简单第八弹:连接Mysql数据库
数据库·python·学习
qq_6543669832 分钟前
如何排查Oracle客户端连接慢_DNS解析超时与sqlnet配置优化
jvm·数据库·python
迷途酱1 小时前
手写一个 AI Agent:从 Function Calling 到自动化任务链
python
Gerardisite1 小时前
企微机器人开发指南
java·python·机器人·自动化·企业微信
城管不管2 小时前
嵌入模型Embedding Model
java·开发语言·python·embedding·嵌入模型
Architect_Lee2 小时前
python3.14.4环境搭建
python
适应规律2 小时前
pointnet 实战
python
慕涯AI2 小时前
Agent 30 课程开发指南 - 第28课
人工智能·python
迷途酱2 小时前
RAG 从零到一:用 Python 给大模型接上你的私有知识库
python