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
相关推荐
微学AI2 小时前
内网穿透的应用-服务器日志出现异常怎么办?Python监控、钉钉告警与远程处理教程
服务器·python·钉钉
_Jimmy_11 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
SamChan9012 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步201512 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
颜酱12 小时前
09 | 重构项目结构
人工智能·python·langchain
kisloy13 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python
Sisphusssss14 小时前
香橙派5plus GPIO
linux·python·ubuntu
颜酱15 小时前
08 | 把维度值同步到 Elasticsearch(生成阶段)
人工智能·python·langchain
hanlin0315 小时前
刷题笔记:力扣第242、349题(哈希表)
笔记·算法·leetcode
久久学姐15 小时前
基础转码学 AI:Java+Python 双语言入门,3 个月可落地实战项目
java·python·ai·转码·实战项目