Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
*/
Loading