https://leetcode.com/problems/number-of-zero-filled-subarrays/description/
Number of Zero-Filled Subarrays - LeetCode
Can you solve this real interview question? Number of Zero-Filled Subarrays - Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums =
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
|
class Solution:
def zeroFilledSubarray(self, nums: List[int]) -> int:
answer = cnt = 0
for i in range(len(nums)):
if nums[i] == 0:
cnt+=1
answer+=cnt
else:
cnt = 0
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1431. Kids With the Greatest Number of Candies (0) | 2023.04.17 |
---|---|
백준 27889 특별한 학교 이름 (0) | 2023.04.04 |
leetcode 1009. Complement of Base 10 Integer (0) | 2023.03.20 |
leetcode 2553. Separate the Digits in an Array (0) | 2023.03.14 |
leetcode 1122. Relative Sort Array (0) | 2023.03.13 |
댓글