给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。
输入: [2,3,-2,4]
输出: 6
输入: [-2,0,-1]
输出: 0
利用动态规划:
function maxProduct(nums){
let n = nums.length;
let front = 1,
back = 1;
let ans = 0;
for(let i = 0; i < n; i++){
front *= nums[i]...
原创
2019-09-04 21:39:59 ·
1372 阅读 ·
0 评论