Skip to content

Commit 9e17838

Browse files
committed
[LEET] 1582 Special Positions in a Binary Matrix (Easy)
1 parent c86d5dd commit 9e17838

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

이용훈/10주차/260304.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @param {number[][]} mat
3+
* @return {number}
4+
*/
5+
var numSpecial = function(mat) {
6+
const m = mat.length;
7+
const n = mat[0].length;
8+
9+
const row = Array(m).fill(0);
10+
const col = Array(n).fill(0);
11+
12+
for (let i = 0; i < m; i++) {
13+
for (let j = 0; j < n; j++) {
14+
if (mat[i][j] === 1) {
15+
row[i]++;
16+
col[j]++;
17+
}
18+
}
19+
}
20+
21+
let answer = 0;
22+
for (let i = 0; i < m; i++) {
23+
if (row[i] !== 1) continue;
24+
25+
for (let j = 0; j < n; j++) {
26+
if (mat[i][j] === 1 && col[j] === 1) answer++;
27+
}
28+
}
29+
30+
return answer;
31+
};

0 commit comments

Comments
 (0)