当前位置:网站首页>2022.02.15 - 240. Lucky number in matrix
2022.02.15 - 240. Lucky number in matrix
2022-06-29 06:16:00 【A CAI continues to work hard】
List of articles
1. subject


2. Ideas
(1) Simulation
- ergodic matrix , Find out the minimum value of each row first , Find out the maximum value of each column , If there are duplicate elements , Indicates that the element is a lucky number .
3. Code
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) {
}
}
class Solution {
public List<Integer> luckyNumbers(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
List<Integer> res = new ArrayList<>();
Set<Integer> set = new HashSet<>();
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]);
}
set.add(min);
}
for (int i = 0; i < n; i++) {
int max = Integer.MIN_VALUE;
for (int j = 0; j < m; j++) {
max = Math.max(max, matrix[j][i]);
}
if (!set.add(max)) {
res.add(max);
}
}
return res;
}
}
边栏推荐
- Hustoj SPJ example
- Honeypot based on MySQL load data local INFILE
- Monitor employee turnover dynamics. This system makes employees tremble!
- 2022 recommended tire industry research report industry development prospect market analysis white paper
- Design risc-v processor from scratch -- data adventure of five stage pipeline
- Difference between static and final
- Is there any difference between a=a+b and a+=b?
- Difference between parametric continuity and geometric continuity
- 51 single chip microcomputer learning notes 7 -- Ultrasonic Ranging
- Common methods for describing 3D models of objects and their advantages and disadvantages
猜你喜欢
![[C language series] - initial C language (4)](/img/3b/b20d6e0194f2114f8c27a17d58369a.jpg)
[C language series] - initial C language (4)

QT writing map comprehensive application 58 compatible with multi browser kernel

Testing grpc service with grpcui

Parsing rshub document auto generation API

Ctrip launched the "3+2" office mode. Are you sour?

Monitor employee turnover dynamics. This system makes employees tremble!

Fresnel diffraction with rectangular aperture based on MATLAB

The generation of leetcode simple questions each character is an odd number of strings

Hustoj SPJ example

Pytest (7) -yield and termination function
随机推荐
Fault: NetBt log for id4321
Manual (functional) test 1
Parsing rshub document auto generation API
Monitor employee turnover dynamics. This system makes employees tremble!
51 lines of code, self-made TX to MySQL software!
[chromium] win10 vs2019 environment chromium configuration and compilation.
Difference between URI and URL
2022 recommended quantum industry research industry development planning prospect investment market analysis report (the attachment is a link to the online disk, and the report is continuously updated
Functions and arrays of shell scripts
It turns out that the joys and sorrows of programmers are not interlinked
How to insert pseudo code into word documents simply and quickly?
Difference between static and final
Hustoj SPJ example
Programming specification and variables of shell script
Two houses with different colors and the farthest distance
Why is there a packaging type?
ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
Fault: ntfrs warning log for id13562
What are the uses of static?
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience