1380.cpp (814B)
1 class Solution { 2 public: 3 vector<int> luckyNumbers(const vector<vector<int>> &matrix) const { 4 static int row[51], col[51]; 5 const int n = size(matrix); 6 const int m = size(matrix[0]); 7 vector<int> res; 8 9 memset(row, 0x7F, sizeof(row)); 10 memset(col, 0x00, sizeof(col)); 11 12 for (int i = 0; i < n; i++) { 13 for (int j = 0; j < m; j++) { 14 row[i] = min(row[i], matrix[i][j]); 15 col[j] = max(col[j], matrix[i][j]); 16 } 17 } 18 19 for (int i = 0; i < n; i++) { 20 for (int j = 0; j < m; j++) { 21 if (row[i] != matrix[i][j]) continue; 22 if (col[j] != matrix[i][j]) continue; 23 res.push_back(matrix[i][j]); 24 } 25 } 26 27 return res; 28 } 29 };