We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b5d2994 commit ad73293Copy full SHA for ad73293
scripts/algorithms/N/Number of ZeroFilled Subarrays/Number of Zero-Filled Subarrays.java
@@ -0,0 +1,16 @@
1
+// Runtime: 5 ms (Top 80.84%) | Memory: 59.7 MB (Top 94.86%)
2
+class Solution {
3
+ public long zeroFilledSubarray(int[] nums) {
4
+ long len = 0;
5
+ long ans = 0;
6
+ for (int i = 0; i < nums.length; i++) {
7
+ if (nums[i] == 0) ++len;
8
+ else if (len > 0) {
9
+ ans += (len * (len + 1)) / 2;
10
+ len = 0;
11
+ }
12
13
+ if (len > 0) ans += (len * (len + 1)) / 2;
14
+ return ans;
15
16
+}
0 commit comments