leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit3c0dee9bfde2225d81c86415f8c5f9b1bf34ee7e
parent3402adb00df1ddf844a2efa280220da428d9f944
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateTue, 7 Feb 2023 16:48:32 +0100

Algorithm II: Day 5

Diffstat:
AProblems/0713.cpp|++++++++++++++++
MREADME.md|+

2 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/Problems/0713.cpp b/Problems/0713.cpp

@@ -0,0 +1,16 @@

class Solution {
public:
int numSubarrayProductLessThanK(vector<int> &nums, int k) {
int res = 0, count = 0, prod = 1, start = 0;
;
for (int i = 0; i < nums.size(); i++) {
prod *= nums[i];
while (prod >= k && start <= i) {
prod /= nums[start++];
count--;
}
res += i - start + 1;
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -248,6 +248,7 @@ for solving problems.

| 0704 | Easy | [Binary Search](Problems/0704.cpp) |
| 0706 | Easy | [Design HashMap](Problems/0706.cpp) |
| 0707 | Medium | [Design Linked List](Problems/0707.cpp) |
| 0713 | Medium | [Subarray Product Less Than K](Problems/0713.cpp) |
| 0714 | Medium | [Best Time to Buy and Sell Stock with Transaction Fee](Problems/0714.cpp) |
| 0724 | Easy | [Find Pivot Index](Problems/0724.cpp) |
| 0733 | Easy | [Flood Fill](Problems/0733.cpp) |