当前位置:网站首页>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 
边栏推荐
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- 嵌入式软件开发
- PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
- . Net, C # basic knowledge
- Linear DP acwing 902 Shortest editing distance
- [opencv learning] [image pyramid]
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- The UVM Primer——Chapter2: A Conventional Testbench for the TinyALU
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
猜你喜欢

Heap acwing 838 Heap sort

Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)

spfa AcWing 851. SPFA finding the shortest path

国产免费数据仓库ETL调度自动化运维专家—TASKCTL

Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
![[opencv learning] [template matching]](/img/4c/7214329a34974c59b4931c08046ee8.jpg)
[opencv learning] [template matching]

阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
![Jerry's watch stops ringing [article]](/img/28/8a225b77b19360d2b0077a2b8c4b6d.jpg)
Jerry's watch stops ringing [article]

Linear DP acwing 902 Shortest editing distance

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
随机推荐
Heap acwing 839 Simulated reactor
[opencv learning] [image pyramid]
接口测试面试题目,你都会了吗?
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
绕过ObRegisterCallbacks需要驱动签名方法
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
PR usage skills, how to use PR to watermark?
[opencv learning] [image filtering]
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
C operator
ADB basic commands
Typora+docsify quick start
上海交大教授:何援军——包围盒(包容体/包围盒子)
moon
Floyd AcWing 854. Floyd finds the shortest path
[opencv learning] [moving object detection]
Jerry's watch stops ringing [article]
C#修饰符