Skip to content

Commit cb66e05

Browse files
committed
💀 [152] Missing edge case - Runtime 62 ms Beats 69.31% Memory 42.2 MB Beats 82.29%
1 parent 3f5e36e commit cb66e05

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

152/my_solution.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const maxProduct = (nums) => {
1111
if (0 === nums[i]) {
1212
min = 1;
1313
max = 1;
14+
if (result < 0) result = 0;
1415
continue;
1516
}
1617

1718
let tmpMax = max;
1819
max = Math.max(nums[i] * min, nums[i] * max, nums[i]);
1920
min = Math.min(nums[i] * min, nums[i] * tmpMax, nums[i])
20-
if (max > result) result = max;
2121
console.log(`max:${max}, min:${min} -- result:${result}`)
2222

2323
}
@@ -27,8 +27,8 @@ const maxProduct = (nums) => {
2727
return result;
2828
};
2929

30-
maxProduct([2, 3, -2, 4])
31-
// maxProduct([-2, 0, -1])
30+
// maxProduct([2, 3, -2, 4])
31+
maxProduct([-2, 0, -1])
3232
// maxProduct([0])
3333
// maxProduct([0, 2])
3434
// maxProduct([-2, 3, -4])

152/solution.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const maxProduct = (nums) => {
99
if (0 === nums[i]) {
1010
min = 1;
1111
max = 1;
12+
if (result < 0) result = 0;
1213
continue;
1314
}
1415

0 commit comments

Comments
 (0)