diff --git a/README.md b/README.md index dc8f5ce..bfcf8ca 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Solutions in various programming languages are provided. Enjoy it. 17. [Robot Bounded In Circle](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/17-Robot-Bounded-In-Circle) 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) 19. [Sequential Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/19-Sequential-Digits) +23. [Gas Station](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/23-Gas-Station) +28. [Subarray Product Less Than K](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K) ## August LeetCoding Challenge Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions. diff --git a/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K/Subarray-Product-Less-Than-K.cs b/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K/Subarray-Product-Less-Than-K.cs new file mode 100644 index 0000000..abf7444 --- /dev/null +++ b/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K/Subarray-Product-Less-Than-K.cs @@ -0,0 +1,17 @@ +public class Solution { + public int NumSubarrayProductLessThanK(int[] nums, int k) { + int len = nums.Length; + int p = 1; + int i=0, j=0, total=0; + while(j < len){ + p *= nums[j]; + while(i<=j && p>=k){ + p /= nums[i]; + i++; + } + total += (j-i+1); + j++; + } + return total; + } +}