aboutsummaryrefslogtreecommitdiff
path: root/num_zero_filled_subarr.py
blob: db8c3b5c05c4fd7c1c19400fa38c3139b553b71b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 2348. Number of Zero-Filled Subarrays

"""
given integer array 'nums', return number of subarrays filled with zero. a
subarray is a contiguous non-empty sequence of elements from within an array
"""


class Solution(object):
    def zeroFilledSubarray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        cnt, streak = 0
        for i in nums:
            if i == 0:
                streak += 1
                cnt += streak
            else:
                streak = 0
        return cnt


if __name__ == "__main__":
    obj = Solution()
    print(obj.zeroFilledSubarray(nums=[1, 3, 0, 0, 2, 0, 0, 4]))
    print(obj.zeroFilledSubarray(nums=[0, 0, 0, 2, 0, 0]))
    print(obj.zeroFilledSubarray(nums=[2, 10, 2019]))