Skip to content

Commit 02a362a

Browse files
authored
Update 1277-count-square-submatrices-with-all-ones.js
1 parent 97a9d6f commit 02a362a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

1277-count-square-submatrices-with-all-ones.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {number}
4+
*/
5+
const countSquares = function (matrix) {
6+
const [m, n] = [matrix.length, matrix[0].length]
7+
let res = 0
8+
for(let i = 0; i < m; i++) {
9+
for(let j = 0; j < n; j++) {
10+
if(matrix[i][j] && i > 0 && j > 0) {
11+
matrix[i][j] = 1 + Math.min(
12+
matrix[i - 1][j],
13+
matrix[i][j - 1],
14+
matrix[i - 1][j - 1],
15+
)
16+
}
17+
res += matrix[i][j]
18+
}
19+
}
20+
return res
21+
}
22+
23+
// another
24+
125
/**
226
* @param {number[][]} matrix
327
* @return {number}

0 commit comments

Comments
 (0)