File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ vector<int> luckyNumbers (vector<vector<int>>& matrix) {
4
+ vector<int> ans;
5
+ bool a = false , b = false;
6
+ int n = matrix.size();
7
+ int m = matrix[0].size();
8
+
9
+ // below loops are for traversing matrix
10
+ for(int i=0;i<n;i++){
11
+ for(int j = 0;j<m;j++){
12
+
13
+ // find minimum element in matrix
14
+ int at = *min_element(matrix[i].begin(),matrix[i].end());
15
+
16
+ // check that min element is this element or not
17
+ if(matrix[i][j] == at)a = true;
18
+
19
+ // now check the column
20
+ int kt = INT_MIN;
21
+
22
+ // check for the max element in that column
23
+ for(int k = 0;k<n;k++){
24
+ if(matrix[k][j]>kt)kt = matrix[k][j];
25
+ }
26
+ // compare with current element
27
+ if(kt == matrix[i][j])b = true;
28
+
29
+ // if both conditions are true , then store the answer
30
+ if(a && b)ans.push_back(matrix[i][j]);
31
+ a = false , b = false;
32
+ }
33
+ }
34
+ return ans;
35
+ }
36
+ };
You can’t perform that action at this time.
0 commit comments