当前位置:网站首页>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
边栏推荐
- Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
- Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
- 阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
- Linear DP acwing 896 Longest ascending subsequence II
- 一些突然迸发出的程序思想(模块化处理)
- About asp Net MVC project in local vs running response time is too long to access, the solution!
- JS generates 4-digit verification code
- js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- Visual studio efficient and practical extension tools and plug-ins
猜你喜欢
Jerry's watch modifies the alarm clock [chapter]
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
ArrayList与LinkedList效率的对比
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
Hash table acwing 840 Simulated hash table
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
随机推荐
Word efficiency guide - word's own template
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
上海交大教授:何援军——包围盒(包容体/包围盒子)
Do you know all the interface test interview questions?
Wechat official account payment prompt MCH_ ID parameter format error
Jerry's watch stops ringing [article]
spfa AcWing 852. SPFA judgement negative ring
JDBC prevent SQL injection problems and solutions [preparedstatement]
Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)
moon
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
获取文件版权信息
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)
Floyd AcWing 854. Floyd finds the shortest path
8A 同步降压稳压器 TPS568230RJER_规格信息
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
正确遍历EntryList方法