Skip to content

Commit 24765c7

Browse files
authored
Create Code Testcase Test Result Test Result 1352. Product of the La… (#715)
2 parents d4478d7 + 0fb3ea6 commit 24765c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ProductOfNumbers {
2+
public:
3+
vector<int> nums;
4+
int n;
5+
ProductOfNumbers() {
6+
nums.clear();
7+
n = 0;
8+
}
9+
10+
void add(int num) { nums.push_back(num); }
11+
12+
int getProduct(int k) {
13+
int n = nums.size();
14+
int prod = 1;
15+
for (int i = n - k; i < n; i++) {
16+
prod *= nums[i];
17+
}
18+
return prod;
19+
}
20+
};
21+
22+
/**
23+
* Your ProductOfNumbers object will be instantiated and called as such:
24+
* ProductOfNumbers* obj = new ProductOfNumbers();
25+
* obj->add(num);
26+
* int param_2 = obj->getProduct(k);
27+
*/

0 commit comments

Comments
 (0)