Skip to content

Commit 9a9d313

Browse files
committed
Feb 14
1 parent 31e8e10 commit 9a9d313

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class ProductOfNumbers:
2+
def __init__(self):
3+
self.products = [1]
4+
5+
def add(self, num: int) -> None:
6+
if num == 0:
7+
self.products = [1]
8+
else:
9+
self.products.append(self.products[-1] * num)
10+
11+
def getProduct(self, k: int) -> int:
12+
if k >= len(self.products):
13+
return 0
14+
return self.products[-1] // self.products[-k-1]
15+
16+
17+
def main():
18+
product_of_numbers = ProductOfNumbers()
19+
product_of_numbers.add(3)
20+
product_of_numbers.add(0)
21+
product_of_numbers.add(2)
22+
product_of_numbers.add(5)
23+
product_of_numbers.add(4)
24+
assert product_of_numbers.getProduct(2) == 20
25+
assert product_of_numbers.getProduct(3) == 40
26+
assert product_of_numbers.getProduct(4) == 0
27+
product_of_numbers.add(8)
28+
assert product_of_numbers.getProduct(2) == 32
29+
30+
31+
if __name__ == '__main__':
32+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
| February 11 | [1910. Remove All Occurrences of a Substring](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/) | Medium | Solved |
1818
| February 12 | [2342. Max Sum of a Pair With Equal Sum of Digits](https://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | Solved |
1919
| February 13 | [3066. Minimum Operations to Exceed Threshold Value II](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii/) | Medium | Solved |
20-
| February 14 | []() | | |
20+
| February 14 | [1352. Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Medium | Unsolved |
2121
| February 15 | []() | | |
2222
| February 16 | []() | | |
2323
| February 17 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 7 | 7 | 0 |
41+
| Medium | 7 | 6 | 1 |
4242
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)