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
相关推荐
米粒18 小时前
力扣算法刷题 Day 27
算法·leetcode·职场和发展
IAUTOMOBILE8 小时前
Python 流程控制与函数定义:从调试现场到工程实践
java·前端·python
Mr_Xuhhh9 小时前
LeetCode hot 100(C++版本)(上)
c++·leetcode·哈希算法
TT_441910 小时前
python程序实现图片截图溯源功能
开发语言·python
小陈的进阶之路10 小时前
logging 日志模块笔记
python
cqbelt10 小时前
Python 并发编程实战学习笔记
笔记·python·学习
穿条秋裤到处跑11 小时前
每日一道leetcode(2026.03.31):字典序最小的生成字符串
算法·leetcode
智算菩萨11 小时前
【论文复现】Applied Intelligence 2025:Auto-PU正例无标签学习的自动化实现与GPT-5.4辅助编程实战
论文阅读·python·gpt·学习·自动化·复现
小陈工12 小时前
2026年3月31日技术资讯洞察:AI智能体安全、异步编程突破与Python运行时演进
开发语言·jvm·数据库·人工智能·python·安全·oracle
老李的勺子12 小时前
Agent 记忆失效的 5 种方式:完整排查复盘
python·llm