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
相关推荐
布语world13 分钟前
某东pc滑块分析
前端·javascript·网络·python·安全
m0_6464299727 分钟前
Python pytest 单元测试基础
python
DeepVisionary42 分钟前
从1秒多压到0.39秒,Gemini 4 Live靠先应声再干活,把语音延迟降了3倍
python·自动化
Web3&Basketball1 小时前
Playwright实战:27B网页智能体评测3步
python·大模型·浏览器自动化·playwright·网页智能体·评测口径·molmoweb
zc.z1 小时前
RAG (一):从底层原理、Naive RAG 到企业级项目开发与面试实战
人工智能·python·rag
Shaoshing1 小时前
LeetCode100 76.最小覆盖字串
java·算法·leetcode
王者鳜錸2 小时前
【中英】-Android离线语音听写-讯飞 AIKit源码实现
开发语言·python·智能手机·安卓·离线中英识别
凌冰_3 小时前
数据结构 - 矩阵(九)
算法·矩阵
Navigator_Z4 小时前
LeetCode //C - 1331. Rank Transform of an Array
c语言·算法·leetcode
BK贝壳4 小时前
浮点值也能挂进混合数组:bool-hybrid-array 的 FloatHybridArray 构造、下标与追加本机实测
开发语言·数据结构·python·性能优化·numpy