Skip to content

Commit 35bffd6

Browse files
committed
Runtime: 164 ms (Top 94.71%) | Memory: 69.9 MB (Top 70.96%)
1 parent 81283a3 commit 35bffd6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/P/Product of the Last K Numbers/Product of the Last K Numbers.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// Runtime: 164 ms (Top 94.71%) | Memory: 69.9 MB (Top 70.96%)
12
class ProductOfNumbers {
23
private:
34
vector<int> prefixProduct;
45
public:
56
ProductOfNumbers() {
6-
7+
78
}
8-
9+
910
void add(int num) {
1011
if(num == 0){
1112
prefixProduct.clear();
@@ -17,7 +18,7 @@ class ProductOfNumbers {
1718
int prod = prefixProduct[prefixProduct.size() - 1] * num;
1819
prefixProduct.push_back(prod);
1920
}
20-
21+
2122
}
2223
int getProduct(int k) {
2324
if(k > prefixProduct.size()){
@@ -27,6 +28,6 @@ class ProductOfNumbers {
2728
if(k == size) return prefixProduct[size - 1];
2829
int prod = prefixProduct[size - 1] / prefixProduct[size - k - 1];
2930
return prod;
30-
31+
3132
}
32-
};
33+
};

0 commit comments

Comments
 (0)