当前位置:网站首页>【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;
}
}
边栏推荐
- 如何访问kubernetes API?
- [shutter] shutter layout component (physicalmodel component)
- 一周生活
- MySQL learning record (9)
- Image segmentation using pixellib
- Infrastructure is code: a change is coming
- [shutter] shutter page Jump (route | navigator | page close)
- Research Report on micro gripper industry - market status analysis and development prospect prediction
- Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
- [Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
猜你喜欢
![[shutter] shutter page Jump (route | navigator | page close)](/img/af/3fb2ca18bcec23a5c0c6897570fb53.gif)
[shutter] shutter page Jump (route | navigator | page close)

《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!

*C language final course design * -- address book management system (complete project + source code + detailed notes)

The neo4j skill tree was officially released to help you easily master the neo4j map database

D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
![[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)](/img/fa/5c1b6c16d9aabd13e9a4f7c7b9c7da.jpg)
[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)

sql service 截取字符串

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

如何访问kubernetes API?

PIP version update timeout - download using domestic image
随机推荐
Construction and maintenance of business website [5]
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
China's Micro SD market trend report, technology dynamic innovation and market forecast
20220702-程序员如何构建知识体系?
Detailed explanation of OSI seven layer model
The failure rate is as high as 80%. What should we do about digital transformation?
Physical layer cables and equipment
The neo4j skill tree was officially released to help you easily master the neo4j map database
MySQL inserts Chinese data and reports an error. Set the default collation
100 important knowledge points that SQL must master: management transaction processing
[Jianzhi offer] 57 And are two numbers of S
Research Report on market supply and demand and strategy of China's plastic pump industry
Micro SD Card Industry Research Report - market status analysis and development prospect forecast
Error in PIP installation WHL file: error: is not a supported wheel on this platform
Market trend report, technical innovation and market forecast of China's Micro pliers
MySQL learning record (4)
Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
[shutter] statefulwidget component (pageview component)
Analysis of neural network
A week's life