We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2123c0c commit 71da372Copy full SHA for 71da372
maximum-product-subarray/mintheon.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ //시간복잡도: O(n)
3
+ //공간복잡도: O(n)
4
+ public int maxProduct(int[] nums) {
5
+ int[] maxValue = new int[nums.length];
6
+ int[] minValue = new int[nums.length];
7
+
8
+ maxValue[0] = nums[0];
9
+ minValue[0] = nums[0];
10
11
+ for(int i = 1; i < nums.length; i++) {
12
+ int value1 = maxValue[i - 1] * nums[i];
13
+ int value2 = minValue[i - 1] * nums[i];
14
15
+ maxValue[i] = Math.max(Math.max(value1, value2), nums[i]);
16
+ minValue[i] = Math.min(Math.min(value1, value2), nums[i]);
17
+ }
18
19
+ int result = Integer.MIN_VALUE;
20
+ for(int i = 0; i < nums.length; i++) {
21
+ result = Math.max(result, maxValue[i]);
22
23
24
+ return result;
25
26
+}
0 commit comments