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
相关推荐
烟花落o2 分钟前
【数据结构系列04】随机链表的复制、环形链表I、环形链表||
数据结构·算法·leetcode·链表
迷之程序员5 分钟前
llama-cpp-python用法,模型加载gpu踩坑全记录
开发语言·python·llama
pursuit_csdn9 小时前
LeetCode 1022. Sum of Root To Leaf Binary Numbers
算法·leetcode·深度优先
nimadan129 小时前
**AI漫剧软件2025推荐,解锁高性价比创意制作新体验**
人工智能·python
踩坑记录10 小时前
leetcode hot100 35. 搜索插入位置 medium 二分查找
leetcode
yunhuibin11 小时前
GoogLeNet学习
人工智能·python·深度学习·神经网络·学习
易辰君12 小时前
【Python爬虫实战】正则:中文匹配与贪婪非贪婪模式详解
开发语言·爬虫·python
秀儿还能再秀12 小时前
正则表达式核心语法 + Python的 re 库中常用方法
python·正则表达式
xcLeigh12 小时前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
-海绵东东-13 小时前
哈希表······················
算法·leetcode·散列表