Skip to content

Commit f39e311

Browse files
authored
Create 2302. Count Subarrays With Score Less Than K
1 parent ad27c7e commit f39e311

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
long long countSubarrays(vector<int>& nums, long long k) {
4+
long long ans = 0, sum = 0;
5+
int left = 0;
6+
for (int right = 0; right < nums.size(); right++) {
7+
sum += nums[right];
8+
while (sum * (right - left + 1) >= k) {
9+
sum -= nums[left++];
10+
}
11+
ans += right - left + 1;
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)