当前位置:网站首页>leetcode-1380. Lucky number in matrix
leetcode-1380. Lucky number in matrix
2022-07-02 03:27:00 【Eager to be the winner of loneliness】
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
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
int m=matrix.length,n=matrix[0].length;
Set<Integer> minSet=new HashSet<>();
List<Integer> res=new ArrayList<>();
for(int i=0;i<m;i++){
int min=Integer.MAX_VALUE;
for(int j=0;j<n;j++){
min=Math.min(min,matrix[i][j]);
}
minSet.add(min);
}
for(int j=0;j<n;j++){
int max=Integer.MIN_VALUE;
for(int i=0;i<m;i++){
max=Math.max(max,matrix[i][j]);
}
if(minSet.contains(max)){
res.add(max);
}
}
return res;
}
}
边栏推荐
- aaaaaaaaaaaaa
- Framing in data transmission
- Aaaaaaaaaaaa
- PY3 link MySQL
- Download and use of the super perfect screenshot tool snipaste
- KL divergence is a valuable article
- Gradle 笔记
- Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
- Work hard all day long and be alert at sunset
- aaaaaaaaaaaaa
猜你喜欢
JS introduction < 1 >
One of the future trends of SAP ui5: embrace typescript
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
Review materials of project management PMP high frequency examination sites (8-1)
命名块 verilog
Verilog 过程连续赋值
ThreadLocal详解
跟着CTF-wiki学pwn——ret2shellcode
Verilog 状态机
This article describes the step-by-step process of starting the NFT platform project
随机推荐
Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU
Download and use of the super perfect screenshot tool snipaste
Learn PWN from CTF wiki - ret2shellcode
ORA-01547、ORA-01194、ORA-01110
4. Find the median of two positive arrays
Kotlin basic learning 17
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
Verilog 避免 Latch
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
MSI announced that its motherboard products will cancel all paper accessories
Pycharm2021 delete the package warehouse list you added
知物由学 | 自监督学习助力内容风控效果提升
只需简单几步 - 开始玩耍微信小程序
Apple added the first iPad with lightning interface to the list of retro products
命名块 verilog
Large screen visualization from bronze to the advanced king, you only need a "component reuse"!
MySQL advanced (Advanced) SQL statement (II)
One of the future trends of SAP ui5: embrace typescript
JDBC details
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added