当前位置:网站首页>Winter vacation daily question - lucky numbers in the matrix
Winter vacation daily question - lucky numbers in the matrix
2022-07-02 13:32:00 【A cat that doesn't eat mice】
- Topic link :https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix/
- Title Description
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
The smallest of all elements in the same row
The largest of all elements in the same column
- Example
Input :matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output :[15]
explain :15 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Ideas
Preprocessing with two arrays , Store the minimum value of each row and the maximum value of each column respectively . Then find the same value in the two arrays .
- Code
public List<Integer> luckyNumbers (int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
int[] rows = new int[m];
int[] cols = new int[n];
Arrays.fill(rows,Integer.MAX_VALUE);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
rows[i] = Math.min(rows[i],matrix[i][j]);
cols[j] = Math.max(cols[j],matrix[i][j]);
}
}
List<Integer> list = new ArrayList<>();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (cols[j]==rows[i])
list.add(rows[i]);
}
}
return list;
}
边栏推荐
- Achievements in science and Technology (27)
- Student course selection information management system based on ssm+jsp framework [source code + database]
- What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- Unity skframework framework (XX), VFX lab special effects library
- Unity skframework framework (XIV), extension extension function
- Three talking about exception -- error handling
- [cloud native database] what to do when encountering slow SQL (Part 1)?
- Why is the default of switch followed by break?
- 不会看器件手册的工程师不是个好厨子
猜你喜欢

2022零代码/低代码开发白皮书【伙伴云出品】附下载

Node. JS accessing PostgreSQL database through ODBC

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

Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
![[OpenGL] notes 29. Advanced lighting (specular highlights)](/img/6e/56bc7237f691a4355f0b7627b3003e.png)
[OpenGL] notes 29. Advanced lighting (specular highlights)

What are eNB, EPC and PGW?
![Jerry's watch modifies the alarm clock [chapter]](/img/d6/04fb8143027578bb707529a05db548.jpg)
Jerry's watch modifies the alarm clock [chapter]
![Jerry's watch delete alarm clock [chapter]](/img/7f/d51b37872b4ce905a0a723a514b2dc.jpg)
Jerry's watch delete alarm clock [chapter]

Can automatically update the universal weekly report template, you can use it with your hand!

Word efficiency guide - word's own template
随机推荐
[Unity]使用GB2312,打包后程序不正常解决方案
题解《子数整数》、《欢乐地跳》、《开灯》
[OpenGL] notes 29. Advanced lighting (specular highlights)
Fundamentals of machine learning (II) -- division of training set and test set
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
JS reverse massive creative signature
Security RememberMe原理分析
PR usage skills, how to use PR to watermark?
Numpy array calculation
mac(macos Monterey12.2 m1) 个人使用php开发
De4000h storage installation configuration
Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
OpenFOAM:lduMatrix&lduAddressing
Principle analysis of security rememberme
SSL证书的分类有哪些?如何选择合适的SSL证书?
中文姓名提取(玩具代码——准头太小,权当玩闹)
Why is the default of switch followed by break?
How much do you know about free SSL certificates? The difference between free SSL certificate and charged SSL certificate
SAP MM 因物料有负库存导致MMPV开账期失败问题之对策
文件的下载与图片的预览