Skip to content

Commit

Permalink
Create Code Testcase Test Result Test Result 1352. Product of the La… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Feb 14, 2025
2 parents d4478d7 + 0fb3ea6 commit 24765c7
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ProductOfNumbers {
public:
vector<int> nums;
int n;
ProductOfNumbers() {
nums.clear();
n = 0;
}

void add(int num) { nums.push_back(num); }

int getProduct(int k) {
int n = nums.size();
int prod = 1;
for (int i = n - k; i < n; i++) {
prod *= nums[i];
}
return prod;
}
};

/**
* Your ProductOfNumbers object will be instantiated and called as such:
* ProductOfNumbers* obj = new ProductOfNumbers();
* obj->add(num);
* int param_2 = obj->getProduct(k);
*/

0 comments on commit 24765c7

Please sign in to comment.