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
相关推荐
诸神缄默不语12 小时前
Python处理Word文档完全指南:从基础到进阶
python
海棠AI实验室12 小时前
第四章 项目目录结构:src/、configs/、data/、tests/ 的黄金布局
python·项目目录结构
爱笑的眼睛1113 小时前
超越可视化:降维算法组件的深度解析与工程实践
java·人工智能·python·ai
清铎14 小时前
leetcode_day12_滑动窗口_《绝境求生》
python·算法·leetcode·动态规划
踩坑记录14 小时前
leetcode hot100 42 接雨水 hard 双指针
leetcode
ai_top_trends14 小时前
2026 年工作计划 PPT 横评:AI 自动生成的优劣分析
人工智能·python·powerpoint
TDengine (老段)14 小时前
TDengine Python 连接器进阶指南
大数据·数据库·python·物联网·时序数据库·tdengine·涛思数据
vyuvyucd14 小时前
深入解析Python asyncio:异步编程核心原理
开发语言·python
brent42314 小时前
DAY50复习日
开发语言·python
万行15 小时前
机器学习&第三章
人工智能·python·机器学习·数学建模·概率论