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
相关推荐
汤姆小白11 小时前
01-环境搭建与项目导览
人工智能·python·机器学习·numpy
伊玛目的门徒15 小时前
试用leetcode之典中典 二数之和问题
java·算法·leetcode
向日的葵00617 小时前
langchain的Tools教程(三)
python·langchain·tools
言乐618 小时前
Python实现可运行解密游戏游戏框架
python·游戏·小程序·游戏程序·关卡设计
YUS云生18 小时前
Python学习笔记·第31天:FastAPI入门——路由、路径参数、查询参数与请求体
笔记·python·学习
旖-旎18 小时前
《LeetCode647 回文子串 || LeetCode 5 最长回文子串》
c++·算法·leetcode·动态规划·哈希算法
智写-AI19 小时前
真实有效的免费降英文AI工具服务商
人工智能·python
yuhuofei202119 小时前
【Python入门】了解掌握Python中函数的基本使用
python
白帽小阳21 小时前
2026前端面试题!(附答案及解析)
javascript·网络·python·安全·web安全·网络安全·护网行动