Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python3

class Solution:
    def zeroFilledSubarray(self, nums: List[int]) -> int:
        subarray,size = 0,0
        for i in range(len(nums)):
            
            if nums[i] == 0:
                size += 1
                
            
            if nums[i]!=0:
                subarray += (size*size -((size-1)*size)/2)
                #also (size*size -((size-1)*size)/2) = (size)(size+1)/2
                size = 0
        
        if nums[len(nums)-1] ==0:
            subarray += (size*size -((size-1)*size)/2)
        return int(subarray)
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
8+4 =