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
相关推荐
alphaTao2 分钟前
LeetCode 每日一题 2026/3/16-2026/3/22
linux·windows·leetcode
空空潍2 分钟前
LeetCode力扣 hot100一刷完结
算法·leetcode
weixin199701080162 分钟前
“迷你京东”全栈架构设计与实现
java·大数据·python·数据库架构
lcreek5 分钟前
LeetCode 1162.地图分析
算法·leetcode·bfs
虚幻如影12 分钟前
Tesseract-OCR 引擎安装
python·ocr
带娃的IT创业者16 分钟前
国内主流大模型API调用入门与对比:DeepSeek/智谱GLM/Kimi/千问完整指南
python·大模型·api调用·kimi·千问·deepseek·智谱glm
Tisfy21 分钟前
LeetCode 3567.子矩阵的最小绝对差:暴力模拟
leetcode·矩阵·题解·模拟·暴力
万粉变现经纪人24 分钟前
如何解决 pip install pillow-simd 报错 需要 AVX2/特定编译器 支持 问题
python·scrapy·beautifulsoup·aigc·pandas·pillow·pip
技术小黑26 分钟前
TensorFlow学习系列08 | 实现猫狗识别
人工智能·python·tensorflow2·vgg-16算法