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
相关推荐
Adios7942 小时前
设置交集大小至少为2
数据结构·算法·leetcode
love530love2 小时前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
cui_ruicheng4 小时前
Python从入门到实战(十六):多进程编程
开发语言·python
_Jimmy_6 小时前
FastAPI + SQLAlchemy全局事务管理
python·fastapi
用户8356290780516 小时前
如何使用 Python 在 Excel 中添加、编辑和删除超链接
后端·python
AC赳赳老秦8 小时前
企业工商公开信息采集分析:OpenClaw 批量查询企业工商信息,生成企业画像报告
大数据·开发语言·python·自动化·php·deepseek·openclaw
FoldWinCard8 小时前
D6 Python 基础语法 --- 保留关键字
开发语言·python
yurenshi16689 小时前
20 账号以内矩阵怎么选?聚媒通、融媒宝、新榜小豆芽、矩阵通功能、价格实测对比
线性代数·矩阵
暮暮祈安9 小时前
Celery 新手入门指南
java·数据库·python·flask·httpx
JustNow_Man9 小时前
每日高频场景英文口语
python