-
Notifications
You must be signed in to change notification settings - Fork 4
/
Solution.cpp
39 lines (35 loc) · 941 Bytes
/
Solution.cpp
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
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <cmath>
using namespace std;
class Solution {
public:
vector<int> luckyNumbers (vector<vector<int>>& matrix) {
vector<int> res;
int m=matrix.size(),n=matrix[0].size();
vector<int> rowmin(m,1<<30), colmax(n,0);
for (int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
if (matrix[i][j] < rowmin[i]) rowmin[i] = matrix[i][j];
if (matrix[i][j] > colmax[j]) colmax[j] = matrix[i][j];
}
}
for (int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
if (matrix[i][j] == rowmin[i] and matrix[i][j] == colmax[j])
res.push_back(matrix[i][j]);
}
}
return res;
}
};
int main() {
Solution s;
return 0;
}