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
相关推荐
小鸡脚来咯16 分钟前
python虚拟环境
开发语言·python
龘龍龙26 分钟前
Python基础(九)
android·开发语言·python
大学生毕业题目1 小时前
毕业项目推荐:91-基于yolov8/yolov5/yolo11的井盖破损检测识别(Python+卷积神经网络)
python·yolo·目标检测·cnn·pyqt·井盖破损
XLYcmy1 小时前
TarGuessIRefined密码生成器详细分析
开发语言·数据结构·python·网络安全·数据安全·源代码·口令安全
weixin_433417672 小时前
Canny边缘检测算法原理与实现
python·opencv·算法
梨落秋霜2 小时前
Python入门篇【元组】
android·数据库·python
i小杨2 小时前
python 项目相关
开发语言·python
weixin_462446232 小时前
使用 Tornado + systemd 搭建图片静态服务(imgserver)
开发语言·python·tornado
别多香了2 小时前
python基础之面向对象&异常捕获
开发语言·python
youngee112 小时前
hot100-61电话号码的字母组合
java·数据结构·leetcode