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
相关推荐
WL_Aurora12 小时前
Python 算法基础篇之排序算法(二):希尔、快速、归并
python·算法·排序算法
RSCompany12 小时前
Frida 17 以后 Python API 跑旧版 JS 报 Java is not defined ?一行 import 直接恢复 Frida 16 体验
开发语言·python·逆向·hook·frida·android逆向·frida17
张道宁12 小时前
从零开始训练YOLO手机检测模型:完整实战教程
python·yolo
快乐的哈士奇12 小时前
对话框打字机效果:Vur + Java/Python 实现
java·开发语言·python
malog_12 小时前
PyTorch图像数据加载实战指南
图像处理·人工智能·pytorch·python
博.闻广见12 小时前
AI_Python基础-4.标准库与IO
开发语言·python
程序猿编码12 小时前
大模型的“文字障眼法“:FlipAttack 文本反转越狱技术全解析
linux·python·ai·大模型
晚烛12 小时前
CANN 数据流与内存优化:L1/L2 缓存机制与计算重叠深度解析
人工智能·python·缓存
xiao5kou4chang6kai412 小时前
如何用Python处理气象海洋数据?台风数据爬取、SST的EOF分析、WRF剖面图绘制
python·气象·台风·wrf·海洋
Reload.12 小时前
CZ航司,shopping JS逆向 acw_sc__v2
开发语言·javascript·python·网络爬虫·ecmascript