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
相关推荐
hyswl6667 分钟前
2025年郑州开发小程序公司推荐
python·小程序
B站计算机毕业设计之家9 分钟前
基于Python音乐推荐系统 数据分析可视化 协同过滤推荐算法 大数据(全套源码+文档)建议收藏✅
python·数据分析·推荐算法
-森屿安年-35 分钟前
LeetCode 283. 移动零
开发语言·c++·算法·leetcode
用户7851278147040 分钟前
实战解析:淘宝/天猫商品描述API(taobao.item_get_desc)接口
python
codists43 分钟前
Pycharm错误:JetBrains AI URL resolution failure
python
青瓷程序设计1 小时前
鱼类识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
该用户已不存在1 小时前
Python正在死去,2026年Python还值得学吗?
后端·python
战南诚2 小时前
flask之“应用上下文,请求上下文”
python·flask
Predestination王瀞潞2 小时前
Windows环境下Pytorch的配置
人工智能·pytorch·python
二川bro2 小时前
特征工程完全手册:2025 Python实战技巧
开发语言·python