当前位置:网站首页>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 
边栏推荐
- JSON serialization and parsing
- Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
- Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
- 阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
- Redis bloom filter
- Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
- Hash table acwing 841 String hash
- Get started REPORT | today, talk about the microservice architecture currently used by Tencent
- 软件测试面试题-2022年大厂面试题合集
- JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
猜你喜欢

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

3 A VTT端接 稳压器 NCP51200MNTXG资料

Heap acwing 839 Simulated reactor

日本赌国运:Web3.0 ,反正也不是第一次失败了!

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本

Async/await asynchronous function
![[opencv learning] [image filtering]](/img/4c/fe22e9cdf531873a04a7c4e266228d.jpg)
[opencv learning] [image filtering]
随机推荐
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
通过反射执行任意类的任意方法
[opencv learning] [image pyramid]
. Net, C # basic knowledge
Finally, someone explained the supervised learning clearly
Hash table acwing 840 Simulated hash table
. Net wechat message template push
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Jerry's weather code table [chapter]
js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)
Fundamentals of face recognition (facenet)
Interview questions for software testing - a collection of interview questions for large factories in 2022
软件测试面试题-2022年大厂面试题合集
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
moon
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Redis bloom filter
Package management tools