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 61e396b

Browse files
Update Number of Zero-Filled Subarrays.java
1 parent 3fbb01a commit 61e396b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
class Solution {
22
public long zeroFilledSubarray(int[] nums) {
3-
long subarrayCount = 0L;
4-
intidx = 0;
5-
while (idx< nums.length) {
6-
longcount = 0L;
7-
while (idx < nums.length && nums[idx] == 0) {
8-
idx++;
9-
count++;
3+
long count = 0;
4+
longrunningCount = 0;
5+
for (inti = 0; i< nums.length; i++) {
6+
if (nums[i] == 0) {
7+
runningCount++;
8+
} else {
9+
runningCount = 0;
1010
}
11-
subarrayCount += (count * (count + 1)) / 2;
12-
idx++;
11+
count += runningCount;
1312
}
14-
return subarrayCount;
13+
return count;
1514
}
1615
}

0 commit comments

Comments
(0)

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