Skip to content

Commit 2c10e7f

Browse files
Sam  LuoSam  Luo
Sam Luo
authored and
Sam Luo
committed
add solution to 2348 number of zero filled subarray
1 parent 406be85 commit 2c10e7f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: javascript/2348-number-of-zero-filled-subarrays.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Time O(N) | Space O(1)
3+
* https://leetcode.com/problems/number-of-zero-filled-subarrays
4+
*/
5+
/**
6+
* @param {number[]} nums
7+
* @return {number}
8+
*/
9+
var zeroFilledSubarray = function(nums) {
10+
let total, count;
11+
total = count = 0;
12+
for(let element of nums){
13+
if(element == 0){
14+
count ++;
15+
total += count;
16+
}else{
17+
count = 0;
18+
}
19+
};
20+
return total;
21+
};

0 commit comments

Comments
 (0)