LeetCode 152. Maximum Product Subarray(最大乘积)

原题网址:https://leetcode.com/problems/maximum-product-subarray/

Find the contiguous subarray within an array (containing at least one number) which has the largest product.

For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest product = 6.

方法:按0将数组分段。

public class Solution {
    private int max(int[] nums, int from, int to, int product) {
        int right = product;
        int max = right;
        int left = 1;
        for(int i=from; i<=to; i++) {
            left *= nums[i];
            right /= nums[i];
            max = Math.max(max, left);
            if (i


你可能感兴趣的:(数组,乘积,最值,分段,切分指针,分段指针,单个指针)