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
相关推荐
Tisfy2 分钟前
LeetCode 1291.顺次数:打表/枚举
算法·leetcode·题解·枚举·遍历
Ivanqhz39 分钟前
DRN(深度强化学习推荐网络)
人工智能·线性代数·机器学习·矩阵·dnn
嘘嘘出差1 小时前
Python 爬虫入门实战:爬取豆瓣电影 Top 250
开发语言·爬虫·python
爱写代码的倒霉蛋1 小时前
实现协程的三种方式
开发语言·python
罗超驿1 小时前
双指针算法详解:从入门到精通(Java版)
算法·leetcode·职场和发展
崖边看雾1 小时前
记录Python学习——第一章环境安装下载(Windows)
windows·python·学习·pycharm
tkevinjd1 小时前
力扣300-最长递增子序列
算法·leetcode·职场和发展·动态规划·贪心
用户298698530142 小时前
Python 实现 Excel 到 ODS、XPS、PostScript 及 PDF/A-1b 的格式转换
后端·python·excel
本地化文档2 小时前
xlwings-docs-l10n
python·github·excel·gitcode·sphinx