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
相关推荐
liuyao_xianhui10 分钟前
优选算法_分治_快速排序_归并排序_C++
开发语言·数据结构·c++·算法·leetcode·排序算法·动态规划
团子和二花24 分钟前
openclaw平替之nanobot源码解析(七):Gateway与多渠道集成
python·gateway·agent·智能体·openclaw·nanobot
未知鱼29 分钟前
Python安全开发之简易目录扫描器(含详细注释)
开发语言·python·安全
Be1k034 分钟前
推荐一款语雀知识库批量导出工具
python·gui·工具·语雀·批量导出·原创
Sunshine for you1 小时前
如何用FastAPI构建高性能的现代API
jvm·数据库·python
阿贵---1 小时前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
Red丶哞2 小时前
内网自建Postfix使用Python发送邮件
开发语言·python
rebekk2 小时前
pytorch custom op的简单介绍
人工智能·pytorch·python
chushiyunen2 小时前
uv使用笔记(python包的管理工具)
笔记·python·uv
曲幽2 小时前
FastAPI状态共享秘籍:别再让中间件、依赖和路由“各自为政”了!
python·fastapi·web·request·state·depends·middleware