-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLC_1380.cpp
More file actions
30 lines (30 loc) · 786 Bytes
/
LC_1380.cpp
File metadata and controls
30 lines (30 loc) · 786 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
30
class Solution {
public:
vector<int> luckyNumbers (vector<vector<int>>& matrix) {
int i,j,rowsz=matrix.size(),colsz=matrix[0].size(),minrow,maxcol;
vector<int>res;
unordered_map<int,int>mp;
for(i=0;i<rowsz;i++)
{
minrow=INT_MAX;
for(j=0;j<colsz;j++)
{
if(matrix[i][j]<minrow)
minrow=matrix[i][j];
}
mp[minrow]=1;
}
for(j=0;j<colsz;j++)
{
maxcol=0;
for(i=0;i<rowsz;i++)
{
if(matrix[i][j]>maxcol)
maxcol=matrix[i][j];
}
if(mp.find(maxcol)!=mp.end())
res.push_back(maxcol);
}
return res;
}
};