Skip to content

Commit cbbabf5

Browse files
committed
docs: Leet_1343_NumberofSubarraysofSizeKandAverageGreaterthanorEqualtoThreshold
1 parent 4348904 commit cbbabf5

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

  • src/ver2/Leet_1343_NumberofSubarraysofSizeKandAverageGreaterthanorEqualtoThreshold
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ver2.Leet_1343_NumberofSubarraysofSizeKandAverageGreaterthanorEqualtoThreshold;
2+
3+
class Solution {
4+
public int numOfSubarrays(int[] arr, int k, int threshold) {
5+
int i = 0;
6+
int j = 0;
7+
int n = arr.length;
8+
int ans = 0;
9+
int sum = 0;
10+
11+
while(j < n){
12+
if(j - i + 1 < k){
13+
sum += arr[j];
14+
j++;
15+
}
16+
else{
17+
sum += arr[j];
18+
19+
if(sum / k >= threshold) ans++;
20+
21+
sum -= arr[i];
22+
23+
i++;
24+
j++;
25+
}
26+
}
27+
return ans;
28+
}
29+
}

0 commit comments

Comments
 (0)