We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 81283a3 commit 35bffd6Copy full SHA for 35bffd6
scripts/algorithms/P/Product of the Last K Numbers/Product of the Last K Numbers.cpp
@@ -1,11 +1,12 @@
1
+// Runtime: 164 ms (Top 94.71%) | Memory: 69.9 MB (Top 70.96%)
2
class ProductOfNumbers {
3
private:
4
vector<int> prefixProduct;
5
public:
6
ProductOfNumbers() {
-
7
+
8
}
9
10
void add(int num) {
11
if(num == 0){
12
prefixProduct.clear();
@@ -17,7 +18,7 @@ class ProductOfNumbers {
17
18
int prod = prefixProduct[prefixProduct.size() - 1] * num;
19
prefixProduct.push_back(prod);
20
21
22
23
int getProduct(int k) {
24
if(k > prefixProduct.size()){
@@ -27,6 +28,6 @@ class ProductOfNumbers {
27
28
if(k == size) return prefixProduct[size - 1];
29
int prod = prefixProduct[size - 1] / prefixProduct[size - k - 1];
30
return prod;
31
32
-};
33
+};
0 commit comments