Skip to content

Commit 62587ed

Browse files
committed
Time: 29 ms (15.38%), Space: 58.3 MB (26.92%) - LeetHub
1 parent fc342a0 commit 62587ed

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const arrSum = arr => {
2+
let cur = 0;
3+
let ans = 0;
4+
const n = arr.length;
5+
for(let i = 0; i < n; i++){
6+
cur = arr[i] === 0 ? 0 : cur + 1;
7+
ans += cur;
8+
}
9+
return ans;
10+
}
11+
/**
12+
* @param {number[][]} mat
13+
* @return {number}
14+
*/
15+
var numSubmat = function(mat) {
16+
const m = mat.length, n = mat[0].length;
17+
let ans = 0;
18+
for(let top = 0; top < m; top++){
19+
const compressed = new Array(n).fill(1);
20+
for(let bottom = top; bottom < m; bottom++){
21+
for(let c = 0; c < n; c++) compressed[c] &= mat[bottom][c];
22+
ans += arrSum(compressed);
23+
}
24+
}
25+
return ans;
26+
};

0 commit comments

Comments
 (0)