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
相关推荐
zhougl9961 分钟前
Java 枚举类(enum)详解
java·开发语言·python
恋爱绝缘体15 分钟前
Java语言提供了八种基本类型。六种数字类型【函数基数噶】
java·python·算法
serve the people8 分钟前
python环境搭建 (三) FastAPI 与 Flask 对比
python·flask·fastapi
断眉的派大星41 分钟前
Python多线程编程全解析
python
铁手飞鹰42 分钟前
[深度学习]Vision Transformer
人工智能·pytorch·python·深度学习·transformer
weixin_395448911 小时前
average_weights.py
pytorch·python·深度学习
蒜香拿铁1 小时前
【第一章】爬虫概述
爬虫·python
ID_180079054731 小时前
Python调用淘宝评论API:从入门到首次采集全流程
服务器·数据库·python
小猪咪piggy1 小时前
【Python】(2) 执行顺序控制语句
开发语言·python
Σdoughty1 小时前
python第三次作业
开发语言·前端·python