当前位置:网站首页>【leetcode】1380. Lucky number in matrix
【leetcode】1380. Lucky number in matrix
2022-07-02 21:52:00 【Chinese fir sauce_】
subject :
1380. The lucky number in the matrix
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
The smallest of all elements in the same row
The largest of all elements in the same column
Example 1:
Input :matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output :[15]
explain :15 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Example 2:
Input :matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output :[12]
explain :12 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Example 3:
Input :matrix = [[7,8],[1,2]]
Output :[7]
Tips :
m == mat.length
n == mat[i].length
1 <= n, m <= 50
1 <= matrix[i][j] <= 10^5
All elements in the matrix are different
violence :
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
List<Integer> list = new ArrayList<>();
for(int i = 0; i < m;i++){
int resMin = Integer.MAX_VALUE;
int idx = 0;
// Traverse each element of the current line to find the minimum value
for(int j = 0; j < n;j++){
resMin = Math.min(resMin,matrix[i][j]);
// Assign the coordinates of the minimum value of the current row to idx
if(resMin == matrix[i][j])idx = j;
}
int resMax = Integer.MIN_VALUE;
// Traverse the current page i The smallest element of the row idx Column by column traversal
for(int j = 0; j < m;j++){
// Roll variables to record
resMax = Math.max(resMax,matrix[j][idx]);
}
// If this value is the minimum value of the current row again idx The maximum value of the column Then he is the lucky number Add it to the result
if(resMax == resMin) list.add(resMin);
}
return list;
}
}
边栏推荐
- 发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
- Evolution of messaging and streaming systems under the native tide of open source cloud
- 地理探测器原理介绍
- 分享一下如何制作专业的手绘电子地图
- Physical layer cables and equipment
- 图像基础概念与YUV/RGB深入理解
- Research Report on plastic antioxidant industry - market status analysis and development prospect forecast
- Record the functions of sharing web pages on wechat, QQ and Weibo
- Chargement de l'image pyqt après décodage et codage de l'image
- : last child does not take effect
猜你喜欢

【零基础一】Navicat下载链接

Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision

Daily book - low code you must understand in the era of digital transformation

MySQL learning record (9)
![[shutter] shutter layout component (physicalmodel component)](/img/6a/f8161fb7c8e9012456622f1920da64.gif)
[shutter] shutter layout component (physicalmodel component)

Introduction to the principle of geographical detector

Basic knowledge of tree and binary tree (detailed illustration)

pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform

Cardinality sorting (detailed illustration)

Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
随机推荐
Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
A specially designed loss is used to deal with data sets with unbalanced categories
MySQL learning record (5)
:last-child 不生效解决
Pyqt picture decodes and encodes and loads pictures
Construction and maintenance of business website [3]
pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
Redis distributed lock failure, I can't help but want to burst
D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
Etcd raft protocol
PIP version update timeout - download using domestic image
【剑指 Offer】57. 和为s的两个数字
MySQL learning record (8)
How do I access the kubernetes API?
MySQL inserts Chinese data and reports an error. Set the default collation
MySQL learning record (2)
Gbase8s database type
Baidu sued a company called "Ciba screen"
Construction and maintenance of business websites [8]
[Jianzhi offer] 57 And are two numbers of S