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
相关推荐
Eric.Lee202115 分钟前
mujoco读取模型几何体属性
python·物理引擎·mujoco·物理仿真·构建物理几何体
子午19 分钟前
【车辆车型识别系统】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积网络+resnet50算法
人工智能·python·深度学习
独行soc24 分钟前
2025年渗透测试面试题总结-273(题目+回答)
网络·python·安全·web安全·网络安全·渗透测试·安全狮
独行soc25 分钟前
2025年渗透测试面试题总结-274(题目+回答)
网络·python·安全·web安全·网络安全·渗透测试·安全狮
CHANG_THE_WORLD28 分钟前
Python列表(List)介绍
windows·python·list
狐5731 分钟前
2025-12-04-LeetCode刷题笔记-2211-统计道路上的碰撞次数
笔记·算法·leetcode
Byron Loong35 分钟前
【Debug】vscode 调试python,如何配置固定调试文件
ide·vscode·python
qq_356196951 小时前
day31函数专题2:装饰器@浙大疏锦行
python
爱学习的梵高先生1 小时前
Python:变量
python
齐齐大魔王1 小时前
python爬虫学习进程(四)
爬虫·python·学习