当前位置:网站首页>Lucky numbers in the [leetcode daily question] matrix
Lucky numbers in the [leetcode daily question] matrix
2022-07-02 13:06:00 【Oysters bring the sea to Chicago】
The lucky number in the matrix
difficulty : Simple 
The minimum value of each line of the record is traversed for the first time , Deposit in set Collection . The second traversal records the maximum value of each column , Deposit in set Collection , When deposit fails , That is, the current element conforms to the rule of lucky number .
The code is as follows :
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> res = new ArrayList<>();
Set<Integer> set = new HashSet<>();
int m = matrix.length;
int n = matrix[0].length;
for (int i = 0; i < m; i++) {
int tmp = Integer.MAX_VALUE;
for (int j = 0; j < n; j++) {
tmp = Math.min(tmp,matrix[i][j]);
}
set.add(tmp);
}
for (int i = 0; i < n; i++) {
int tmp = Integer.MIN_VALUE;
for (int j = 0; j < m; j++) {
tmp = Math.max(tmp,matrix[j][i]);
}
if (!set.add(tmp)){
res.add(tmp);
}
}
return res;
}
Execution results : success 
边栏推荐
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Variable, "+" sign, data type
- Interval DP acwing 282 Stone merging
- About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- 3 a VTT terminal regulator ncp51200mntxg data
- Counting class DP acwing 900 Integer partition
- 一些突然迸发出的程序思想(模块化处理)
- The redis development document released by Alibaba covers all redis operations
- 移动式布局(流式布局)
猜你喜欢

Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
![Jerry's watch time synchronization [chapter]](/img/64/a48772b4e503ae0a2d36fc292e4e0d.jpg)
Jerry's watch time synchronization [chapter]

spfa AcWing 852. SPFA judgement negative ring

Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)

Linear DP acwing 897 Longest common subsequence

Async/await asynchronous function

Five best software architecture patterns that architects must understand

js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)

Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf

Modular commonjs es module
随机推荐
JS generates 4-digit verification code
Five best software architecture patterns that architects must understand
Execute any method of any class through reflection
net share
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
Jerry's weather direction coding table [chapter]
Hundreds of web page special effects can be used. Don't you come and have a look?
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
JS iterator generator asynchronous code processing promise+ generator - > await/async
Typora+docsify quick start
VIM super practical guide collection of this one is enough
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
C#运算符
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
PR usage skills, how to use PR to watermark?
About the loading of layer web spring layer components, the position of the layer is centered
(6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
Jerry's watch stops ringing [article]