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
相关推荐
知识中的海王2 小时前
js逆向入门图灵爬虫练习平台第六题
python
碳基学AI2 小时前
北京大学DeepSeek内部研讨系列:AI在新媒体运营中的应用与挑战|122页PPT下载方法
大数据·人工智能·python·算法·ai·新媒体运营·产品运营
forestsea3 小时前
Python进阶编程总结
开发语言·python·notepad++
袖清暮雨3 小时前
Python刷题笔记
笔记·python·算法
熬夜造bug4 小时前
LeetCode Hot100 刷题笔记(1)—— 哈希、双指针、滑动窗口
笔记·leetcode·hot100
乌旭4 小时前
AI芯片混战:GPU vs TPU vs NPU的算力与能效博弈
人工智能·pytorch·python·深度学习·机器学习·ai·ai编程
MinggeQingchun4 小时前
Python - 爬虫-网页抓取数据-库requests
爬虫·python·requests
拓端研究室TRL5 小时前
Python贝叶斯回归、强化学习分析医疗健康数据拟合截断删失数据与参数估计3实例
开发语言·人工智能·python·数据挖掘·回归
wolf犭良6 小时前
27、Python 数据库操作入门(SQLite)从基础到实战精讲
数据库·python·sqlite