This is my CPP solution.
class Solution {
public:
int numSpecial(vector<vector<int>>& mat) {
vector<vector<int>> tr;
for(int i=0;i<mat.size();i++){
for(int j=0;j<mat[i].size();j++) {
if(mat[i][j] == 1) {
tr.push_back({i, j});
}
}
}
int cnt = tr.size();
for(int i=0;i<tr.size();i++){
for(int j=0; j<tr.size(); j++){
if(i!=j) {
if(tr[i][0] == tr[j][0] || tr[i][1] == tr[j][1]){
cnt--;
break;
}
}
}
}
return cnt;
}
};