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
相关推荐
曲幽5 小时前
FastAPI + PostgreSQL 实战:从入门到不踩坑,一次讲透
python·sql·postgresql·fastapi·web·postgres·db·asyncpg
用户83562907805110 小时前
使用 C# 在 Excel 中创建数据透视表
后端·python
码路飞13 小时前
FastMCP 实战:一个 .py 文件,给 Claude Code 装上 3 个超实用工具
python·ai编程·mcp
dev派15 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪17 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户03321266636717 小时前
将 PDF 文档转换为图片【Python 教程】
python
xlp666hub17 小时前
Leetcode第五题:用C++解决盛最多水的容器问题
linux·c++·leetcode
悟空爬虫18 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派19 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风20 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python