class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> ans = new LinkedList<>();
int M = matrix.length, N = matrix[0].length;
int[] minimumRow = new int[M], maximumCol = new int[N];
Arrays.fill(minimumRow, Integer.MAX_VALUE);
Arrays.fill(maximumCol, Integer.MIN_VALUE);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
minimumRow[i] = Math.min(minimumRow[i], matrix[i][j]);
maximumCol[j] = Math.max(maximumCol[j], matrix[i][j]);
}
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
if (matrix[i][j] == minimumRow[i] && matrix[i][j] == maximumCol[j]) ans.add(matrix[i][j]);
}
}
return ans;
}
}