leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1352.cpp (356B)


0 class ProductOfNumbers {
1 vector<long long> prefix = {1};
3 public:
4 void add(int num) {
5 if (num == 0)
6 prefix = {1};
7 else
8 prefix.push_back(num * prefix.back());
9 }
11 int getProduct(int k) {
12 if (k >= prefix.size()) return 0;
13 return prefix.back() / prefix[prefix.size() - k - 1];
14 }
15 };