-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1380.cpp
More file actions
29 lines (25 loc) · 814 Bytes
/
Copy path1380.cpp
File metadata and controls
29 lines (25 loc) · 814 Bytes
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
class Solution {
public:
vector<int> luckyNumbers(const vector<vector<int>> &matrix) const {
static int row[51], col[51];
const int n = size(matrix);
const int m = size(matrix[0]);
vector<int> res;
memset(row, 0x7F, sizeof(row));
memset(col, 0x00, sizeof(col));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
row[i] = min(row[i], matrix[i][j]);
col[j] = max(col[j], matrix[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (row[i] != matrix[i][j]) continue;
if (col[j] != matrix[i][j]) continue;
res.push_back(matrix[i][j]);
}
}
return res;
}
};