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
相关推荐
simon_skywalker4 分钟前
线性代数及其应用习题答案(中文版)第二章 矩阵代数 2.1 矩阵运算(2)
线性代数·算法·矩阵
_一路向北_33 分钟前
爬虫框架:Feapder使用心得
爬虫·python
皇族崛起1 小时前
【3D标注】- Unreal Engine 5.7 与 Python 交互基础
python·3d·ue5
你想知道什么?1 小时前
Python基础篇(上) 学习笔记
笔记·python·学习
Swizard2 小时前
速度与激情:Android Python + CameraX 零拷贝实时推理指南
android·python·ai·移动开发
一直跑2 小时前
Liunx服务器centos7离线升级内核(Liunx服务器centos7.9离线/升级系统内核)
python
leocoder2 小时前
大模型基础概念入门 + 代码实战(实现一个多轮会话机器人)
前端·人工智能·python
Buxxxxxx2 小时前
DAY 37 深入理解SHAP图
python
ada7_2 小时前
LeetCode(python)108.将有序数组转换为二叉搜索树
数据结构·python·算法·leetcode
请一直在路上2 小时前
python文件打包成exe(虚拟环境打包,减少体积)
开发语言·python