mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
add codeforces solutions folder
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
class Solution {
|
||||
public:
|
||||
int numSpecial(vector<vector<int>>& mat) {
|
||||
int m = mat.size();
|
||||
int n = mat[0].size();
|
||||
vector<int> rowCount(m, 0);
|
||||
vector<int> colCount(n, 0);
|
||||
|
||||
for (int row = 0; row < m; row++) {
|
||||
for (int col = 0; col < n; col++) {
|
||||
if (mat[row][col] == 1) {
|
||||
rowCount[row]++;
|
||||
colCount[col]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
for (int row = 0; row < m; row++) {
|
||||
for (int col = 0; col < n; col++) {
|
||||
if (mat[row][col] == 1) {
|
||||
if (rowCount[row] == 1 && colCount[col] == 1) {
|
||||
ans++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user