当前位置:网站首页>【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;
}
}
边栏推荐
- Research Report on market supply and demand and strategy of China's plastic pump industry
- [C language] [sword finger offer article] - replace spaces
- Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
- 加了定位的文字如何水平垂直居中
- 【剑指 Offer】57. 和为s的两个数字
- Landingsite eband B1 smoke test case
- Jar package startup failed -mysql modify the default port number / set password free enter
- How to center the positioned text horizontally and vertically
- Summary of the first week of summer vacation
- [shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
猜你喜欢
MySQL learning record (4)
[shutter] shutter page Jump (route | navigator | page close)
From personal heroes to versatile developers, the era of programmer 3.0 is coming
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
The difference between include < > and include ""
tinymce可视化编辑器增加百度地图插件
MySQL learning record (8)
It is said that this year gold three silver four has become gold one silver two..
[shutter] shutter layout component (physicalmodel component)
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
随机推荐
Research Report on plastic antioxidant industry - market status analysis and development prospect forecast
Blue Bridge Cup Eliminate last one (bit operation, code completion)
B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
MySQL learning record (4)
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
Pyqt picture decodes and encodes and loads pictures
Etcd Raft 协议
Cloud computing technology [1]
Redis分布式锁故障,我忍不住想爆粗...
How to center the positioned text horizontally and vertically
tinymce可视化编辑器增加百度地图插件
Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
LandingSite eBand B1冒烟测试用例
Error in PIP installation WHL file: error: is not a supported wheel on this platform
Basic knowledge of tree and binary tree (detailed illustration)
MySQL learning record (6)
技术人创业:失败不是成功,但反思是
[shutter] shutter layout component (opacity component | clipprect component | padding component)