Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e9febb

Browse files
Number of Zero-Filled Subarrays
1 parent d4ce4b3 commit 6e9febb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Link: https://leetcode.com/problems/number-of-zero-filled-subarrays/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
10+
public class Solution {
11+
public long ZeroFilledSubarray(int[] nums)
12+
{
13+
long totalCounter = 0;
14+
long counter = 0;
15+
16+
for (int i = 0; i < nums.Length + 1; i++)
17+
{
18+
if (i < nums.Length && nums[i] == 0)
19+
counter++;
20+
else
21+
{
22+
if (counter == 1)
23+
totalCounter += 1;
24+
else
25+
totalCounter += (counter + 1) * counter / 2;
26+
27+
counter = 0;
28+
}
29+
}
30+
31+
return totalCounter;
32+
}
33+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /