Skip to content

Commit 8c77e92

Browse files
committed
Time: 116 ms (29.01%), Space: 91.8 MB (63.09%) - LeetHub
1 parent 85eecf2 commit 8c77e92

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int numSubarrayProductLessThanK(vector<int>& nums, int k) {
4+
int n = nums.size();
5+
int prod = 1;
6+
int cnt = 0;
7+
8+
for(int i = 0, j = 0; j < n; j++){
9+
prod *= nums[j];
10+
// validate the prod
11+
while(i <= j and prod >= k)
12+
prod /= nums[i++];
13+
cnt += j - i + 1;
14+
}
15+
16+
return cnt;
17+
}
18+
};

0 commit comments

Comments
 (0)