2348. Number of Zero-Filled Subarrays
https://leetcode.com/problems/number-of-zero-filled-subarrays
Python
class Solution:
def zeroFilledSubarray(self, nums: List[int]) -> int:
segments = []
count = 0
for i, num in enumerate(nums):
if num == 0:
count += 1
continue
if count:
segments.append(count)
count = 0
if count:
segments.append(count)
# Trapezoidal area
return sum([(n**2 + n)//2 for n in segments])