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
相关推荐
jufeng130736 分钟前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 11 篇】
python·ai agent·mcp
想吃火锅10051 小时前
【leetcode】200. 岛屿数量
算法·leetcode·职场和发展
En^_^Joy1 小时前
Django项目配置全攻略:settings配置文件
后端·python·django
Nil2081 小时前
leetcode 54螺旋矩阵
算法·leetcode·矩阵
for_ever_love__2 小时前
python基础语法学习: 异常的传递性
开发语言·python·学习
AC赳赳老秦2 小时前
公开图片 OCR 数据提取:OpenClaw 合规采集公开信息图,识别文字与表格并转化为结构化数据
java·大数据·前端·数据库·python·php·openclaw
麻雀飞吧3 小时前
零基础选量化工具,先把问题说清楚
人工智能·python
段一凡-华北理工大学3 小时前
AI推动工业智能化转型~系列文章20:工业 AI 平台架构:云-边-端协同的技术体系
人工智能·python·架构·工业平台·云-边协同
CodeBlog-star3 小时前
Harness Engineering:Pi Agent 架构深度解析
人工智能·python·架构·harness工程