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
相关推荐
羲云网络5 小时前
GPT Image 2.6 标注引导编辑:透明 PNG、markup 请求与局部验收
图像处理·人工智能·python·api
富贵儿9985 小时前
NL2SQL 实践手记 09:答案正确以后,还能更快吗——一次可核对的 AI4DB 实验
数据库·python·sql·ai·自然语言处理·langchain
小赖同学啊5 小时前
多模态 一般组合方案
python
劲夫学编程5 小时前
leetcode: 字母异位词分组
算法·leetcode
AI创界者5 小时前
Python 进阶实战(第八十五章):基于 Redis Lua 原子租约的分布式锁、看门狗续期与本地事务表/Outbox 一致性实战
人工智能·python·aigc
wy_hhxx5 小时前
[Leetcode] 动态规划(打家劫舍、0-1背包、完全背包)
算法·leetcode·动态规划·完全背包·0-1背包
Shaoshing6 小时前
LeetCode100 32.最长有效括号
java·数据结构·leetcode
weixin_307779136 小时前
Jupyter SQL 表血缘分析并导出 Excel
开发语言·python·sql·算法·excel
benchmark_cc6 小时前
如何用 Python 计算盈亏痛苦比(Gain-to-Pain Ratio)?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
sbjdhjd6 小时前
后端编程语言 PHP 笔记(第 1–3 章)|PHP 简介、版本与运行环境安装
开发语言·人工智能·笔记·后端·python·ai·php