Skip to content

Commit d43bf6b

Browse files
committed
Time: 6 ms (97.22%), Space: 57.2 MB (97.22%) - LeetHub
1 parent e91a6d6 commit d43bf6b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {number}
4+
*/
5+
var countSquares = function(matrix) {
6+
const m = matrix.length;
7+
const n = matrix[0].length;
8+
let ans = 0;
9+
for(let r = 0; r < m; r++){
10+
for(let c = 0; c < n; c++){
11+
if(r > 0 && c > 0 && matrix[r][c] > 0){
12+
matrix[r][c] = 1 + Math.min(matrix[r-1][c], matrix[r-1][c-1], matrix[r][c-1]);
13+
}
14+
ans += matrix[r][c];
15+
}
16+
}
17+
return ans;
18+
};

0 commit comments

Comments
 (0)