Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit466334e

Browse files
refactor 1352
1 parentda92bcb commit466334e

File tree

1 file changed

+3
-36
lines changed

1 file changed

+3
-36
lines changed

‎src/main/java/com/fishercoder/solutions/_1352.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,11 @@
33
importjava.util.ArrayList;
44
importjava.util.List;
55

6-
/**
7-
* 1352. Product of the Last K Numbers
8-
*
9-
* Implement the class ProductOfNumbers that supports two methods:
10-
* 1. add(int num)
11-
* Adds the number num to the back of the current list of numbers.
12-
* 2. getProduct(int k)
13-
* Returns the product of the last k numbers in the current list.
14-
* You can assume that always the current list has at least k numbers.
15-
* At any time, the product of any contiguous sequence of numbers will fit into a single 32-bit integer without overflowing.
16-
*
17-
* Example:
18-
* Input
19-
* ["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]
20-
* [[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]
21-
* Output
22-
* [null,null,null,null,null,null,20,40,0,null,32]
23-
* Explanation
24-
* ProductOfNumbers productOfNumbers = new ProductOfNumbers();
25-
* productOfNumbers.add(3); // [3]
26-
* productOfNumbers.add(0); // [3,0]
27-
* productOfNumbers.add(2); // [3,0,2]
28-
* productOfNumbers.add(5); // [3,0,2,5]
29-
* productOfNumbers.add(4); // [3,0,2,5,4]
30-
* productOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers is 5 * 4 = 20
31-
* productOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40
32-
* productOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0
33-
* productOfNumbers.add(8); // [3,0,2,5,4,8]
34-
* productOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32
35-
*
36-
* Constraints:
37-
* There will be at most 40000 operations considering both add and getProduct.
38-
* 0 <= num <= 100
39-
* 1 <= k <= 40000
40-
* */
416
publicclass_1352 {
427
publicstaticclassSolution1 {
43-
/**credit: https://leetcode.com/problems/product-of-the-last-k-numbers/discuss/510260/JavaC%2B%2BPython-Prefix-Product*/
8+
/**
9+
* credit: https://leetcode.com/problems/product-of-the-last-k-numbers/discuss/510260/JavaC%2B%2BPython-Prefix-Product
10+
*/
4411
publicstaticclassProductOfNumbers {
4512

4613
List<Integer>list;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp