当前位置:网站首页>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;
}
}
边栏推荐
- 只需简单几步 - 开始玩耍微信小程序
- halcon图像矫正
- [数据库]JDBC
- Verilog wire type
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- Qt的网络连接方式
- Named block Verilog
- [C Advanced] brother Peng takes you to play with strings and memory functions
- Gradle notes
- Download and use of the super perfect screenshot tool snipaste
猜你喜欢

Generate random numbers that obey normal distribution

OSPF LSA message parsing (under update)

Large screen visualization from bronze to the advanced king, you only need a "component reuse"!

Uniapp uses canvas to generate posters and save them locally

C shallow copy and deep copy

In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews

表单自定义校验规则

Pointer array & array pointer

SAML2.0 notes (I)
On redis (II) -- cluster version
随机推荐
Global and Chinese market of autotransfusion bags 2022-2028: Research Report on technology, participants, trends, market size and share
Verilog reg register, vector, integer, real, time register
Sentry experience and architecture, a fledgling monitoring product with a market value of $100million
"Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
h5中的页面显示隐藏执行事件
Aaaaaaaaaaaa
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
Merge interval, linked list, array
Framing in data transmission
Continuous assignment of Verilog procedure
Verilog 避免 Latch
终日乾乾,夕惕若厉
Just a few simple steps - start playing wechat applet
Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
spark调优
C#联合halcon脱离halcon环境以及各种报错解决经历
Screenshot literacy tool download and use
《MATLAB 神经网络43个案例分析》:第42章 并行运算与神经网络——基于CPU/GPU的并行神经网络运算
流线线使用阻塞还是非阻塞