Skip to content

Commit

Permalink
Sync LeetCode submission - Special Positions in a Binary Matrix (cpp)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeeptosarkar committed Dec 13, 2023
1 parent 76d3ee7 commit a2a7dc0
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
};

0 comments on commit a2a7dc0

Please sign in to comment.