当前位置:网站首页>【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;
}
}
边栏推荐
- Plastic granule Industry Research Report - market status analysis and development prospect forecast
- Etcd Raft 协议
- Research Report on micro gripper industry - market status analysis and development prospect prediction
- B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
- Redis distributed lock failure, I can't help but want to burst
- Analysis of neural network
- Infrastructure is code: a change is coming
- Research Report on market supply and demand and strategy of China's plastic pump industry
- China microporous membrane filtration market trend report, technological innovation and market forecast
- The neo4j skill tree was officially released to help you easily master the neo4j map database
猜你喜欢
Infrastructure is code: a change is coming
MySQL learning record (5)
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
PIP audit: a powerful security vulnerability scanning tool
MySQL learning record (7)
From personal heroes to versatile developers, the era of programmer 3.0 is coming
GEE:(二)对影像进行重采样
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
Off chip ADC commissioning record
随机推荐
PIP version update timeout - download using domestic image
Technical solution of vision and manipulator calibration system
记录一下微信、QQ、微博分享web网页功能
PIP audit: a powerful security vulnerability scanning tool
Construction and maintenance of business websites [7]
Une semaine de vie
Structure array, pointer and function and application cases
[C language] [sword finger offer article] - replace spaces
[shutter] shutter layout component (opacity component | clipprect component | padding component)
Unity3D学习笔记4——创建Mesh高级接口
: last child does not take effect
From personal heroes to versatile developers, the era of programmer 3.0 is coming
CVPR论文解读 | 弱监督的高保真服饰模特生成
【剑指 Offer】56 - I. 数组中数字出现的次数
treevalue——Master Nested Data Like Tensor
情感计算与理解研究发展概述
Record the functions of sharing web pages on wechat, QQ and Weibo
Construction and maintenance of business websites [4]
VictoriaMetrics 简介
100 important knowledge points that SQL must master: management transaction processing