We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9617429 commit 258edcbCopy full SHA for 258edcb
solution/0152.Maximum Product Subarray/Solution.java
@@ -0,0 +1,15 @@
1
+class Solution {
2
+ public int maxProduct(int[] nums) {
3
+ int max[] = new int[nums.length];
4
+ int min[] = new int[nums.length];
5
+ int res = nums[0];
6
+ max[0] = min[0] = nums[0];
7
+ for(int i=1;i<nums.length;i++){
8
+ int num = nums[i];
9
+ max[i] = Math.max(Math.max(max[i-1]*num,min[i-1]*num),num);
10
+ min[i] = Math.min(Math.min(min[i-1]*num,max[i-1]*num),num);
11
+ res = Math.max(max[i],res);
12
+ }
13
+ return res;
14
15
+}
0 commit comments