当前位置:网站首页>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;
}
}
边栏推荐
- C reflection practice
- Use blocking or non blocking for streamline
- Learn PWN from CTF wiki - ret2shellcode
- Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
- Qualcomm platform wifi-- WPA_ supplicant issue
- Go execute shell command
- [database]jdbc
- ORA-01547、ORA-01194、ORA-01110
- 数据传输中的成帧
- Pointer array & array pointer
猜你喜欢
《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
Verilog 过程赋值 区别 详解
Getting started with MQ
Continuous assignment of Verilog procedure
Download and use of the super perfect screenshot tool snipaste
汇率的查询接口
Kubernetes cluster storageclass persistent storage resource core concept and use
OSPF LSA message parsing (under update)
Detailed explanation of ThreadLocal
Uniapp uses canvas to generate posters and save them locally
随机推荐
微信小程序中 在xwml 中使用外部引入的 js进行判断计算
Verilog 线型wire 种类
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
Load different fonts in QML
GSE104154_ scRNA-seq_ fibrotic MC_ bleomycin/normalized AM3
Verilog reg register, vector, integer, real, time register
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
Uniapp uses canvas to generate posters and save them locally
Pointer array & array pointer
verilog REG 寄存器、向量、整数、实数、时间寄存器
On redis (II) -- cluster version
PHP array processing
流线线使用阻塞还是非阻塞
ORA-01547、ORA-01194、ORA-01110
C reflection practice
Verilog 过程连续赋值
SAML2.0 笔记(一)
In depth interpretation of pytest official documents (26) customized pytest assertion error information
Discrimination between sap Hana, s/4hana and SAP BTP
This article describes the step-by-step process of starting the NFT platform project