We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc342a0 commit 62587edCopy full SHA for 62587ed
1628-count-submatrices-with-all-ones/1628-count-submatrices-with-all-ones.js
@@ -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
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
26
+};
0 commit comments