当前位置:网站首页>Lucky numbers in the [leetcode daily question] matrix
Lucky numbers in the [leetcode daily question] matrix
2022-07-02 13:06:00 【Oysters bring the sea to Chicago】
The lucky number in the matrix
difficulty : Simple
The minimum value of each line of the record is traversed for the first time , Deposit in set Collection . The second traversal records the maximum value of each column , Deposit in set Collection , When deposit fails , That is, the current element conforms to the rule of lucky number .
The code is as follows :
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> res = new ArrayList<>();
Set<Integer> set = new HashSet<>();
int m = matrix.length;
int n = matrix[0].length;
for (int i = 0; i < m; i++) {
int tmp = Integer.MAX_VALUE;
for (int j = 0; j < n; j++) {
tmp = Math.min(tmp,matrix[i][j]);
}
set.add(tmp);
}
for (int i = 0; i < n; i++) {
int tmp = Integer.MIN_VALUE;
for (int j = 0; j < m; j++) {
tmp = Math.max(tmp,matrix[j][i]);
}
if (!set.add(tmp)){
res.add(tmp);
}
}
return res;
}
Execution results : success
边栏推荐
- 架构师必须了解的 5 种最佳软件架构模式
- 上海交大教授:何援军——包围盒(包容体/包围盒子)
- Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
- Unity SKFramework框架(十九)、POI 兴趣点/信息点
- net share
- About asp Net MVC project in local vs running response time is too long to access, the solution!
- Mobile layout (flow layout)
- Typora+docsify quick start
- 模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
猜你喜欢
[opencv learning] [template matching]
Apply lnk306gn-tl converter, non isolated power supply
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
VIM super practical guide collection of this one is enough
[opencv learning] [Canny edge detection]
通过反射执行任意类的任意方法
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
spfa AcWing 851. SPFA finding the shortest path
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
随机推荐
JS iterator generator asynchronous code processing promise+ generator - > await/async
C modifier
Oracle从入门到精通(第4版)
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
Redis sentinel mechanism and configuration
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
上海交大教授:何援军——包围盒(包容体/包围盒子)
(6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
[opencv learning] [image filtering]
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
应用LNK306GN-TL 转换器、非隔离电源
PR usage skills, how to use PR to watermark?
[error record] cannot open "XXX" because Apple cannot check whether it contains malware
Browser storage scheme
Oracle from entry to mastery (4th Edition)
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
自主可控三维云CAD:CrownCAD赋能企业创新设计