Skip to content

Commit 89a75cf

Browse files
2348: Number of Zero-Filled Subarrays
1 parent 49903da commit 89a75cf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def zeroFilledSubarray(self, nums) -> int:
3+
count = 0
4+
i = 0
5+
while i < len(nums):
6+
if nums[i] == 0:
7+
j = i
8+
while j < len(nums) and nums[j] == 0:
9+
j += 1
10+
count += (j - i) * (j - i + 1) // 2
11+
i = j
12+
else:
13+
i = i+1
14+
15+
return count

0 commit comments

Comments
 (0)