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
相关推荐
前端精髓6 小时前
结构化输出with_structured_output(抽卡)
python·langchain
文丑颜不良啊6 小时前
LeetCode1481~1500题目解析
java·leetcode
尹人入圣7 小时前
目前热门的IP驱动产业新场景新工具
网络·python·网络协议·tcp/ip
文丑颜不良啊7 小时前
LeetCode1381~1400题目解析
java·leetcode
Nuanyt8 小时前
Agent 学习笔记(下篇三):上线工程、进阶选择与操作界面(Stage 7 / 7.5 / 8 + 延伸路线)
笔记·python·学习·memory·aiagent·harness
吴卫斌8 小时前
定投ETF实战指南(四):行业/主题ETF——定投的“进攻端“
开发语言·python·股票·量化
2601_967987378 小时前
Python——入门级(定义功能def函数)
python·函数·可变参数·默认参数·关键字参数
专注仿真10 小时前
梯度提升类(XFBoost)算法详解与代码实例
开发语言·人工智能·python·算法·大模型训练·控制算法
外收内放10 小时前
Python基础语法练习题(75)
开发语言·python·学习
Tisfy11 小时前
LeetCode 3882.网格图中最小异或路径:动态规划
算法·leetcode·动态规划