当前位置:网站首页>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;
}
边栏推荐
- Daily question: 1175 Prime permutation
- What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
- Can automatically update the universal weekly report template, you can use it with your hand!
- PR usage skills, how to use PR to watermark?
- Why can't d link DLL
- Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
- leetcode621. task scheduler
- de4000h存储安装配置
- (6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
- Three talking about exception -- error handling
猜你喜欢

Gee learning notes 2

What are eNB, EPC and PGW?
![Jerry's watch time synchronization [chapter]](/img/64/a48772b4e503ae0a2d36fc292e4e0d.jpg)
Jerry's watch time synchronization [chapter]

How to modify the error of easydss on demand service sharing time?

Redis database persistence
![Jerry's watch delete alarm clock [chapter]](/img/7f/d51b37872b4ce905a0a723a514b2dc.jpg)
Jerry's watch delete alarm clock [chapter]
![[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术](/img/a7/44609a5acf25021f1fca566c3d8c90.png)
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术

Error function ERF

题解:《你的飞碟在这儿》、《哥德巴赫猜想》

We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
随机推荐
SSL证书的分类有哪些?如何选择合适的SSL证书?
What are eNB, EPC and PGW?
[indomitable medal activity] life goes on and writing goes on
JS逆向之巨量创意signature签名
2022零代码/低代码开发白皮书【伙伴云出品】附下载
[Unity]使用GB2312,打包后程序不正常解决方案
Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
2022 zero code / low code development white paper [produced by partner cloud] with download
Unity SKFramework框架(十二)、Score 计分模块
Word efficiency guide - word's own template
TVOC, VOC, VOCs gas detection + Solution
Unity skframework framework (XXI), texture filter map resource filtering tool
OpenAPI generator: simplify the restful API development process
Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
Unity skframework framework (XIII), question module
题解《子数整数》、《欢乐地跳》、《开灯》
Crowncad (crown CAD), the first fully independent 3D CAD platform based on Cloud Architecture in China
Explanation of 34 common terms on the Internet
Jerry's watch ringtone audition [article]
Jerry's watch time synchronization [chapter]