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 小时前
Python简单网络爬虫教程
爬虫·python
mmmmath_38 小时前
LeetCode.541.反转字符串II
数据结构·算法·leetcode
Navigator_Z8 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
Patrick在香港8 小时前
Claude Prompt 香港场景:公文里「今日」落在 6 个日历日上,「翌日」锚错了 5 天
python·自然语言处理·正则表达式·claude·数据清洗
YsyaaabB9 小时前
Python 数值分析
python
阿洛学长9 小时前
计算机二级 Python 基本操作题(15 分)真题笔记(0101 ~ 1903 全套)
python·pycharm
weixin199701080169 小时前
[特殊字符]️《二手ERP对接电商平台的总体方案:统一数据模型 + 事件驱动 + 灰度上线6原则》(附Python源码)
大数据·python
滚雪球~10 小时前
量化交易 防止Windows电脑自动更新并重启
python·量化
参.商.10 小时前
【Day 53】76. 最小覆盖子串
leetcode·golang
L@ncor11 小时前
第二章可能出现的问题
人工智能·python