We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dfa04d6 commit 34d2e4eCopy full SHA for 34d2e4e
1 file changed
src/main/java/com/thealgorithms/dynamicprogramming/MaximumProductSubarray.java
@@ -33,14 +33,14 @@ public static int maxProduct(int[] nums) {
33
return 0;
34
}
35
36
- int maxProduct = nums[0];
37
- int currentMax = nums[0];
38
- int currentMin = nums[0];
+ long maxProduct = nums[0];
+ long currentMax = nums[0];
+ long currentMin = nums[0];
39
40
for (int i = 1; i < nums.length; i++) {
41
// Swap currentMax and currentMin if current number is negative
42
if (nums[i] < 0) {
43
- int temp = currentMax;
+ long temp = currentMax;
44
currentMax = currentMin;
45
currentMin = temp;
46
@@ -53,6 +53,6 @@ public static int maxProduct(int[] nums) {
53
maxProduct = Math.max(maxProduct, currentMax);
54
55
56
- return maxProduct;
+ return (int) maxProduct;
57
58
0 commit comments