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
相关推荐
10年前端老司机12 分钟前
Milvus 8种检索能力实践
数据库·python·agent
Sakura_j_h_1 小时前
从零写一个 MCP stdio Server:用 Python 校验博客文章格式
开发语言·python·自动化·ai工具·mcp·json-rpc
大草原的小灰灰1 小时前
LLM应用的标准开发框架LangChain(八)- 中间件
python·中间件·langchain
卷无止境1 小时前
百万 token 时代的真相:主流大模型上下文窗口与最大输出的横向对比分析
人工智能·python
用户298698530142 小时前
Python 实战:将 HTML 批量转换为 Markdown
python·html·markdown
文丑颜不良啊2 小时前
LeetCode2241~2260题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode2321~2340题目解析
java·leetcode
hhcgchpspk2 小时前
flask服务端页面预防被爬措施
后端·python·flask·网络爬虫·防爬
小小张说故事2 小时前
Python 里 copy.copy() 和 deepcopy() 到底差在哪:拆开 __copy__、__deepcopy__ 和那个防止无限递归的 memo 字典
python
vipxieliang2 小时前
Python collections:高效容器与实战案例
后端·python