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 小时前
Langchain 浅出
python·langchain·llm
smj2302_7968265212 小时前
解决leetcode第3753题范围内总波动值II
python·算法·leetcode
mortimer13 小时前
破局视频翻译【最后一公里】––从语音克隆到口型对齐的完整工程思路
python·github·aigc
门框研究员15 小时前
解锁Python的强大能力:深入理解描述符
python
leoufung16 小时前
LeetCode 92 反转链表 II 全流程详解
算法·leetcode·链表
子不语18016 小时前
Python——函数
开发语言·python
daidaidaiyu16 小时前
一文入门 LangChain 开发
python·ai
im_AMBER17 小时前
Leetcode 59 二分搜索
数据结构·笔记·学习·算法·leetcode
JJ1M817 小时前
用 Python 快速搭建一个支持 HTTPS、CORS 和断点续传的文件服务器
服务器·python·https
leoufung17 小时前
LeetCode 61. 旋转链表(Rotate List)题解与思路详解
leetcode·链表·list