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
相关推荐
重启编程之路1 分钟前
python 基础学习socket -TCP编程
网络·python·学习·tcp/ip
云和数据.ChenGuang1 小时前
pycharm怎么将背景换成白色
ide·python·pycharm
少许极端1 小时前
算法奇妙屋(十二)-优先级队列(堆)
数据结构·算法·leetcode·优先级队列··图解算法
我的xiaodoujiao2 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 25--数据驱动--参数化处理 Excel 文件 2
前端·python·学习·测试工具·ui·pytest
DO_Community2 小时前
基于AI Agent模板:快速生成 SQL 测试数据
人工智能·python·sql·ai·llm·ai编程
Kuo-Teng3 小时前
LeetCode 118: Pascal‘s Triangle
java·算法·leetcode·职场和发展·动态规划
Q_Q5110082853 小时前
python+django/flask的宠物用品系统vue
spring boot·python·django·flask·node.js·php
hmbbcsm4 小时前
练习python题目小记(五)
开发语言·python
蓝桉~MLGT4 小时前
Python学习历程——文件
python·学习·策略模式