-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1380.cpp
More file actions
24 lines (24 loc) · 754 Bytes
/
1380.cpp
File metadata and controls
24 lines (24 loc) · 754 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
class Solution {
public:
vector<int> luckyNumbers (vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
vector<int> rowMin(m, INT_MAX);
vector<int> colMax(n, INT_MIN);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
rowMin[i] = min(rowMin[i], matrix[i][j]);
colMax[j] = max(colMax[j], matrix[i][j]);
}
}
vector<int> res;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (matrix[i][j] == rowMin[i] && matrix[i][j] == colMax[j]) {
res.push_back(matrix[i][j]);
}
}
}
return res;
}
};