题目
类型:数组
解题思路
创建两个数组 row 和 col 用于进行预处理,row[x] 含义为第 x 行的最小值,col[y] 为第 y 列的最大值。
代码
class Solution {int N = 55;int[] row = new int[N], col = new int[N];public List<Integer> luckyNumbers (int[][] mat) {int n = mat.length, m = mat[0].length;for (int i = 0; i < n; i++) {row[i] = 100001;for (int j = 0; j < m; j++) {row[i] = Math.min(row[i], mat[i][j]);col[j] = Math.max(col[j], mat[i][j]);}}List<Integer> ans = new ArrayList<>();for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {int t = mat[i][j];if (t == row[i] && t == col[j]) ans.add(t);}}return ans;}}
