
😎풀이
mat
를 전체 순회
1-1. 현재 셀이 0
이라면, 무시
1-2. 현재 셀이 1
이라면, 해당 열과 행에 1
의 수를 증가
mat
를 전체 재순회
2-1. 현재 셀이 0
이라면, 무시
2-2. 현재 셀이 1
이라면, 같은 행과 열에 단 하나의 1
만 있었는지 검증
2-3. 단 하나의 1
이라면, specials
증가
specials
의 수 반환환
function numSpecial(mat: number[][]): number {
let specials = 0
const n = mat.length
const m = mat[0].length
const rows = Array(n).fill(0)
const cols = Array(m).fill(0)
for(let row = 0; row < n; row++) {
for(let col = 0; col < m; col++) {
if(!mat[row][col]) continue
rows[row]++
cols[col]++
}
}
for(let row = 0; row < n; row++) {
for(let col = 0; col < m; col++) {
if(!mat[row][col]) continue
if(rows[row] > 1) continue
if(cols[col] > 1) continue
specials++
}
}
return specials
};