class Solution {
public int numSpecial(int[][] mat) {
int n = mat.length, m = mat[0].length;
int[] row = new int[n];
int[] col = new int[m];
// 计算出行和列出现1的个数
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
row[i] += mat[i][j];
col[j] += mat[i][j];
}
}
int res = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (mat[i][j] == 1 && row[i] == 1 && col[j] == 1){
res++;
}
}
}
return res;
}
}
力扣:1582. 二进制矩阵中的特殊位置
最新推荐文章于 2024-08-31 00:26:34 发布