题目:1582. 二进制矩阵中的特殊位置
思路:记录每行每列1的个数
class Solution {
public:
int numSpecial(vector<vector<int>>& mat) {
int res = 0;
int rowNum = mat.size();
int colNum = mat[0].size();
vector<int> row(rowNum,0);
vector<int> col(colNum,0);
for(int i = 0;i < rowNum;++i){
for(int j=0;j < colNum;++j){
if(mat[i][j] == 1){
row[i]++;
col[j]++;
}
}
}
for(int i = 0;i < rowNum;++i){
for(int j=0;j < colNum;++j){
if(mat[i][j] == 1 && row[i] == 1 && col[j] == 1){
++res;
}
}
}
return res;
}
};