mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
33 lines
936 B
C++
33 lines
936 B
C++
class Solution{
|
|
public:
|
|
int numSpecial(vector<vector<int>> &mat){
|
|
int ans = 0;
|
|
int r = mat.size();
|
|
int c = mat[0].size();
|
|
for(int row=0;row<r;row++){
|
|
for(int col = 0;col<c;col++){
|
|
if(mat[row][col]==0) continue;
|
|
bool good = true;
|
|
for(int m = 0;m<r;m++){
|
|
if(m!=row && mat[m][col] == 1){
|
|
good = false;
|
|
break;
|
|
}
|
|
}
|
|
for(int n = 0;n<c;n++){
|
|
if(n!=col && mat[row][n] == 1){
|
|
good = false;
|
|
break;
|
|
}
|
|
}
|
|
if(good) ans++;
|
|
|
|
|
|
}
|
|
}
|
|
return ans;
|
|
}
|
|
};
|
|
|
|
//TC : o(r.c(r+c)) SC: o(1)
|