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
相关推荐
py有趣23 分钟前
力扣热门100题之环形链表
算法·leetcode·链表
GIS兵墩墩31 分钟前
postgis--PostgreSQL16及其plpython3u扩展
python·postgis
new Object ~31 分钟前
LangChain的短期记忆存储实现
python·langchain
魔都吴所谓34 分钟前
【Python】从零构建:IP地理位置查询实战指南
开发语言·python·tcp/ip
py有趣35 分钟前
力扣热门100题之回文链表
算法·leetcode·链表
测试19981 小时前
使用Python自动化生成接口测试用例
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
智算菩萨2 小时前
【Pygame】第10章 游戏状态管理与场景切换机制
python·游戏·pygame
songcream12 小时前
TensorFlow的一些基本概念
人工智能·python·tensorflow
AI逐月3 小时前
解决 ComfyUI 插件安装后 Nanobind 报错问题:soxr 版本冲突原理解读
开发语言·python