Skip to content

Commit 62180d8

Browse files
committed
Added Special Positions in a Binary Matrix.java
1 parent 081651f commit 62180d8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int numSpecial(int[][] mat) {
3+
int[] rowCount = new int[mat.length];
4+
int[] colCount = new int[mat[0].length];
5+
for (int i = 0; i < mat.length; i++) {
6+
for (int j = 0; j < mat[0].length; j++) {
7+
if (mat[i][j] == 1) {
8+
rowCount[i]++;
9+
colCount[j]++;
10+
}
11+
}
12+
}
13+
int count = 0;
14+
for (int i = 0; i < mat.length; i++) {
15+
for (int j = 0; j < mat[0].length; j++) {
16+
if (mat[i][j] == 1 && rowCount[i] == 1 && colCount[j] == 1) {
17+
count++;
18+
}
19+
}
20+
}
21+
return count;
22+
}
23+
}

0 commit comments

Comments
 (0)