(nums)
| 18 | * @return {number} |
| 19 | */ |
| 20 | var maxProduct = function (nums) { |
| 21 | if (!nums.length) return 0; |
| 22 | let maxEnding = nums[0]; |
| 23 | let minEnding = nums[0]; |
| 24 | let res = nums[0]; |
| 25 | for (let i = 1; i < nums.length; i++) { |
| 26 | if (nums[i] < 0) { |
| 27 | let temp = minEnding; |
| 28 | minEnding = maxEnding; |
| 29 | maxEnding = temp; |
| 30 | } |
| 31 | |
| 32 | maxEnding = Math.max(maxEnding * nums[i], nums[i]); |
| 33 | minEnding = Math.min(minEnding * nums[i], nums[i]); |
| 34 | res = Math.max(res, maxEnding); |
| 35 | } |
| 36 | return res; |
| 37 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected