diff --git a/Code Testcase Test Result Test Result 1352. Product of the Last K Numbers b/Code Testcase Test Result Test Result 1352. Product of the Last K Numbers new file mode 100644 index 0000000..3b73d5e --- /dev/null +++ b/Code Testcase Test Result Test Result 1352. Product of the Last K Numbers @@ -0,0 +1,27 @@ +class ProductOfNumbers { +public: + vector 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); + */