当前位置:网站首页>leetcode-1380. Lucky number in matrix
leetcode-1380. Lucky number in matrix
2022-07-02 03:27:00 【Eager to be the winner of loneliness】
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
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
int m=matrix.length,n=matrix[0].length;
Set<Integer> minSet=new HashSet<>();
List<Integer> res=new ArrayList<>();
for(int i=0;i<m;i++){
int min=Integer.MAX_VALUE;
for(int j=0;j<n;j++){
min=Math.min(min,matrix[i][j]);
}
minSet.add(min);
}
for(int j=0;j<n;j++){
int max=Integer.MIN_VALUE;
for(int i=0;i<m;i++){
max=Math.max(max,matrix[i][j]);
}
if(minSet.contains(max)){
res.add(max);
}
}
return res;
}
}
边栏推荐
- MySQL advanced (Advanced) SQL statement (II)
- Qualcomm platform WiFi -- P2P issue (2)
- Load different fonts in QML
- Detailed explanation of the difference between Verilog process assignment
- SAML2.0 笔记(一)
- 数据库文件逻辑结构形式指的是什么
- 流线线使用阻塞还是非阻塞
- Verilog reg register, vector, integer, real, time register
- Learn PWN from CTF wiki - ret2shellcode
- ORA-01547、ORA-01194、ORA-01110
猜你喜欢

初出茅庐市值1亿美金的监控产品Sentry体验与架构

Failed to upgrade schema, error: “file does not exist

Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials

Download and use of the super perfect screenshot tool snipaste

JS <2>

C reflection practice

uniapp 使用canvas 生成海报并保存到本地
![[HCIA continuous update] overview of dynamic routing protocol](/img/03/83c883afb63b7c63f6879b5513bac3.jpg)
[HCIA continuous update] overview of dynamic routing protocol

Verilog 状态机
随机推荐
What is hybrid web containers for SAP ui5
Aaaaaaaaaaaa
spark调优
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
Verilog parallel block implementation
halcon图像矫正
C shallow copy and deep copy
Failed to upgrade schema, error: “file does not exist
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
数据库文件逻辑结构形式指的是什么
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Kotlin 基础学习13
只需简单几步 - 开始玩耍微信小程序
"Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
This article describes the step-by-step process of starting the NFT platform project
Pointer array & array pointer
Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
uniapp 使用canvas 生成海报并保存到本地
Load different fonts in QML