Skip to content

Commit 52cdd25

Browse files
Create 1582-special-positions-in-a-binary-matrix.java
1 parent b329f41 commit 52cdd25

File tree

1 file changed

+27
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)