当前位置:网站首页>【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;
}
}
边栏推荐
- Gee: (II) resampling the image
- beginning
- 【剑指 Offer】57. 和为s的两个数字
- Five message formats of OSPF
- Landingsite eband B1 smoke test case
- 关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
- Research Report on market supply and demand and strategy of China's Plastic Geogrid industry
- 如何访问kubernetes API?
- Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
- Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
猜你喜欢

pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform

Structure array, pointer and function and application cases

MySQL learning record (4)

20220702-程序员如何构建知识体系?

VictoriaMetrics 简介

Etcd raft protocol

D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)

Image segmentation using pixellib

Redis distributed lock failure, I can't help but want to burst

System (hierarchical) clustering method and SPSS implementation
随机推荐
B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
Construction and maintenance of business websites [8]
Plastic granule Industry Research Report - market status analysis and development prospect forecast
Three chess games
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
tinymce可视化编辑器增加百度地图插件
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
Cloud computing technology [1]
Off chip ADC commissioning record
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
MySQL learning record (5)
Structure array, pointer and function and application cases
Gee: (II) resampling the image
[shutter] shutter layout component (physicalmodel component)
一周生活
[sword finger offer] 56 - I. the number of numbers in the array
pyqt图片解码 编码后加载图片
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
[Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II