当前位置:网站首页>[leectode 2022.2.15] lucky numbers in the matrix
[leectode 2022.2.15] lucky numbers in the matrix
2022-07-03 02:44:00 【Procedural ape does not lose hair 2】
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 1:
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 .
Example 2:
Input :matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output :[12]
explain :12 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Example 3:
Input :matrix = [[7,8],[1,2]]
Output :[7]
Tips :
m == mat.length
n == mat[i].length
1 <= n, m <= 50
1 <= matrix[i][j] <= 10^5
All elements in the matrix are different
java Code :
class Solution {
// Pretreated every 行 Array of minimum values \textit{minRow}minRow And an array of maximum values per column \textit{maxCol}maxCol,
// among \textit{minRow}[i]minRow[i] It means the first one ii 行 The minimum value of ,\
//textit{maxCol}[j]maxCol[j] It means the first one jj The maximum value of the column .
// ergodic matrix \textit{matrix}matrix, If \textit{matrix}[i][j]matrix[i][j] At the same time satisfy \textit{matrix}[i][j]=\textit{minRow}[i]matrix[i][j]=minRow[i] and \textit{matrix}[i][j] = \textit{maxCol}[j]matrix[i][j]=maxCol[j], that \textit{matrix}[i][j]matrix[i][j] Is the lucky number in the matrix , Add the returned results .
public List<Integer> luckyNumbers (int[][] matrix) {
int m = matrix.length, n = matrix[0].length;
int[] minRow = new int[m];
Arrays.fill(minRow, Integer.MAX_VALUE);
int[] maxCol = new int[n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
minRow[i] = Math.min(minRow[i], matrix[i][j]);
maxCol[j] = Math.max(maxCol[j], matrix[i][j]);
}
}
List<Integer> ret = new ArrayList<Integer>();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == minRow[i] && matrix[i][j] == maxCol[j]) {
ret.add(matrix[i][j]);
}
}
}
return ret;
}
}
边栏推荐
- 2022-2028 global splicing display industry research and trend analysis report
- 《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- Gbase 8C create user / role example 2
- The Linux server needs to install the agent software EPS (agent) database
- 当lambda没有输入时,是何含义?
- Basic operation of binary tree (C language version)
- Gbase 8C system table PG_ amproc
- SQL Server Query spécifie la structure de la table
- tensor中的append应该如何实现
猜你喜欢
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

Random shuffle note
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/7e/ad9ea78868126b149bd9f15f587e6c.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

Choose it when you decide
![[hcia]no.15 communication between VLANs](/img/59/a467c5920cbccb72040f39f719d701.jpg)
[hcia]no.15 communication between VLANs

怎么将yolov5中的PANet层改为BiFPN
![[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)](/img/04/88ce45d370a2e6052c2fce558aa531.jpg)
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)

"Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b

Check log4j problems using stain analysis

Pytest (6) -fixture (Firmware)
随机推荐
JS的装箱和拆箱
Classes and objects - initialization and cleanup of objects - constructor call rules
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
Gbase 8C system table PG_ cast
tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
搭建私有云盘 cloudreve
Apple releases MacOS 11.6.4 update: mainly security fixes
GBase 8c系统表-pg_collation
Kubernetes cluster log and efk architecture log scheme
How to implement append in tensor
GBase 8c系统表-pg_amproc
SQL Server Query spécifie la structure de la table
Can netstat still play like this?
Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
Gbase 8C system table PG_ authid
How to change the panet layer in yolov5 to bifpn