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
相关推荐
楚疏笃21 分钟前
纯Python 实现 Word 文档转换 Markdown
python·word
谅望者30 分钟前
数据分析笔记08:Python编程基础-数据类型与变量
数据库·笔记·python·数据分析·概率论
mortimer35 分钟前
【实战复盘】 PySide6 + PyTorch 偶发性“假死”?由多线程转多进程
pytorch·python·pyqt
清静诗意36 分钟前
Django REST Framework(DRF)RESTful 最完整版实战教程
python·django·restful·drf
studytosky1 小时前
深度学习理论与实战:Pytorch基础入门
人工智能·pytorch·python·深度学习·机器学习
长不大的蜡笔小新2 小时前
手写数字识别:从零搭建神经网络
人工智能·python·tensorflow
前进的李工2 小时前
LeetCode hot100:094 二叉树的中序遍历:从递归到迭代的完整指南
python·算法·leetcode·链表·二叉树
ins_lizhiming2 小时前
在华为910B GPU服务器上运行DeepSeek-R1-0528模型
人工智能·pytorch·python·华为
bwz999@88.com3 小时前
win10安装miniforge+mamba替代miniconda
python
吃着火锅x唱着歌3 小时前
LeetCode 面试题 16.24.数对和
算法·leetcode·职场和发展