当前位置:网站首页>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(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- (6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
- Linear DP acwing 898 Number triangle
- Some sudden program ideas (modular processing)
- js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
- Docsify deploy IIS
- Jerry's weather code table [chapter]
- Wechat official account payment prompt MCH_ ID parameter format error
- Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
- Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
猜你喜欢

Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)

The redis development document released by Alibaba covers all redis operations

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

VIM super practical guide collection of this one is enough

Everyone wants to eat a broken buffet. It's almost cold

JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)

Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment

js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)

The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
随机推荐
Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)
Linear DP acwing 899 Edit distance
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
Interesting interview questions
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
. Net wechat message template push
日本赌国运:Web3.0 ,反正也不是第一次失败了!
嵌入式软件开发
[opencv learning] [moving object detection]
Hundreds of web page special effects can be used. Don't you come and have a look?
移动式布局(流式布局)
Hash table acwing 841 String hash
绕过ObRegisterCallbacks需要驱动签名方法
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
Floyd AcWing 854. Floyd finds the shortest path
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
Get started REPORT | today, talk about the microservice architecture currently used by Tencent
Interview questions for software testing - a collection of interview questions for large factories in 2022