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
相关推荐
console.log('npc')18 分钟前
将 Figma 接入 Codex MCP:从 `/plugins` 到本地插件配置的完整教程
前端·人工智能·python·figma·code·codex·mcp
资深流水灯工程师22 分钟前
PySide6 QMainWindow与QWidget秒解
开发语言·python
popcorn_min27 分钟前
California Housing 可复现回归实验:随机森林预测加州房价
python
吴佳浩 Alben29 分钟前
pytorch 你不学?_EP01_环境准备与安装验证
人工智能·pytorch·python
XiaoZhangGOGOGO30 分钟前
新的文本编辑方式
python
言存36 分钟前
力扣热题283 移动零
数据结构·算法·leetcode
留白_40 分钟前
pandas练习题
python·数据分析·pandas
码界索隆1 小时前
Python转Java系列:面向对象基础
java·开发语言·python
逻辑星辰1 小时前
x-ds-pow-response逆向分析
开发语言·人工智能·python·深度学习·算法
c_lb72881 小时前
涨跌停与流动性变差还要不要挂单:quote 涨跌停字段与熔断思路
python·区块链