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
相关推荐
2301_7820404513 小时前
CSS Flex布局中如何实现导航栏与Logo的左右分布_利用justify-content- space-between
jvm·数据库·python
yaoxin52112313 小时前
400. Java 文件操作基础 - 使用 Buffered Stream I/O 读取文本文件
java·开发语言·python
用户83562907805113 小时前
使用 Python 自动创建 Excel 折线图
后端·python
小白学大数据14 小时前
面向大规模爬取:Python 全站链接爬虫优化(过滤 + 断点续爬)
开发语言·爬虫·python
WL_Aurora14 小时前
【每日一题】贪心
python·算法
IT策士15 小时前
Python 中间件系列:redis 深入浅出
redis·python·中间件
Dxy123931021615 小时前
Python Pillow库:`img.format`与`img.mode`的区别详解
开发语言·python·pillow
༒࿈南林࿈༒15 小时前
刺猬猫小说下载
python·js逆向
星星码️15 小时前
LeetCode刷题简单篇之反转字母
c++·算法·leetcode
.柒宇.16 小时前
AI-Agent入门实战-AI私厨
人工智能·python·langchain·agent·fastapi