首页 热点 要闻 国内 产业 财经 滚动 理财 股票

世界快讯:LeetCode 2661. First Completely Painted Row or Column

2023-06-22 15:26:15 来源 : 哔哩哔哩

You are given a 0-indexed integer array arr, and an m x ninteger matrix matarrand matboth contain all the integers in the range [1, m * n].


(资料图片)

Go through each index iin arrstarting from index 0and paint the cell in matcontaining the integer arr[i].

Return the smallest index iat which either a row or a column will be completely painted in mat.

Example 1:

Input: arr = [1,3,4,2], mat = [[1,4],[2,3]]

Output: 2

Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].

Example 2:

Input: arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]

Output: 3

Explanation: The second column becomes fully painted at arr[3].

Constraints:

m == mat.length

n = mat[i].length

arr.length == m * n

1 <= m, n <= 105

1 <= m * n <= 105

1 <= arr[i], mat[r][c] <= m * n

All the integers of arrare unique.

All the integers of matare unique.

中文翻译:

给你一个下标从 0 开始的整数数组 arr 和一个 m x n 的整数 矩阵 mat 。arr 和 mat 都包含范围 [1,m * n] 内的 所有 整数。

从下标 0 开始遍历 arr 中的每个下标 i ,并将包含整数 arr[i] 的 mat 单元格涂色。

请你找出 arr 中在 mat 的某一行或某一列上都被涂色且下标最小的元素,并返回其下标 i 。

多用hash;

下面是代码:

Runtime: 90 ms, faster than 11.53% of Java online submissions for First Completely Painted Row or Column.

Memory Usage: 80.3 MB, less than 7.42% of Java online submissions for First Completely Painted Row or Column.

关键词:
相关文章

最近更新
家庭自制土豆泥? 2023-06-22 14:56:55
精彩推送
肥肉就是脂肪吗? 2023-06-22 15:34:54