-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1380.矩阵中的幸运数.java
44 lines (34 loc) · 976 Bytes
/
1380.矩阵中的幸运数.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* @lc app=leetcode.cn id=1380 lang=java
*
* [1380] 矩阵中的幸运数
*/
// @lc code=start
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> res=new ArrayList<>();
int row=matrix.length;
int col=matrix[0].length;
for(int i=0;i<row;i++){
int j;
int jmin=0;//每行最小数字的列index
int min=Integer.MAX_VALUE;
for(j=0;j<col;j++){
if(matrix[i][j]<min){
min=matrix[i][j];
jmin=j;
}
}
for(int k=0;k<row;k++){
if(matrix[k][jmin]>matrix[i][jmin]){
break;
}
if(k==row-1){
res.add(matrix[i][jmin]);
}
}
}
return res;
}
}
// @lc code=end