8000 Merge pull request #287 from hellomrsun/master · MetricVoid/Leetcode@7e24e8b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e24e8b

Browse files
authored
Merge pull request AlgoStudyGroup#287 from hellomrsun/master
Add Subarray Product Less Than K
2 parents 21832b1 + 63130b5 commit 7e24e8b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Solutions in various programming languages are provided. Enjoy it.
2626
17. [Robot Bounded In Circle](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/17-Robot-Bounded-In-Circle)
2727
18. [Best Time to Buy and Sell Stock](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/18-Best-Time-to-Buy-and-Sell-Stock)
2828
19. [Sequential Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/19-Sequential-Digits)
29+
23. [Gas Station](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/23-Gas-Station)
30+
28. [Subarray Product Less Than K](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K)
2931

3032
## August LeetCoding Challenge
3133
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
public int NumSubarrayProductLessThanK(int[] nums, int k) {
3+
int len = nums.Length;
4+
int p = 1;
5+
int i=0, j=0, total=0;
6+
while(j < len){
7+
p *= nums[j];
8+
while(i<=j && p>=k){
9+
p /= nums[i];
10+
i++;
11+
}
12+
total += (j-i+1);
13+
j++;
14+
}
15+
return total;
16+
}
17+
}

0 commit comments

Comments
 (0)
0