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
相关推荐
2301_781833524 分钟前
Python 正则表达式入门教程
开发语言·python·正则表达式
copyer_xyf28 分钟前
Agent Tool 调用
后端·python·agent
Amo Xiang35 分钟前
SpiderDemo 第5题:OB混淆实战 —— 反调试绕过与 signature 签名还原
python·js逆向·爬虫逆向·反调试·spiderdemo·ob混淆
copyer_xyf37 分钟前
Agent 结构化输出
后端·python·agent
FBI HackerHarry浩1 小时前
Ollama如何安装到D盘
python·ai
人道领域1 小时前
【LeetCode刷题日记】47.全排列Ⅱ
java·开发语言·算法·leetcode
Navigator_Z1 小时前
LeetCode //C - 1095. Find in Mountain Array
c语言·算法·leetcode
DXM05211 小时前
第13期|遥感语义分割模型:U-Net核心原理+遥感落地优势
人工智能·python·深度学习·目标检测·随机森林·机器学习·支持向量机
码来的小朋友1 小时前
[python] 我开发了一个有20个关卡随机地图的迷宫游戏
python·游戏·pygame
夏天测1 小时前
微信小程序自动化漏洞挖掘流水线:从缓存提取到密钥验证全流程实战
python·网络安全·微信小程序·漏洞挖掘