From 0fb3ea6f0e076d7fb5ff018bd2cb76fdeb88c0dd Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 14 Feb 2025 23:18:41 +0530 Subject: [PATCH] Create Code Testcase Test Result Test Result 1352. Product of the Last K Numbers --- ...Result 1352. Product of the Last K Numbers | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Code Testcase Test Result Test Result 1352. Product of the Last K Numbers 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); + */