java.lang.Object
g0101_0200.s0152_maximum_product_subarray.Solution

public class Solution extends Object
152 - Maximum Product Subarray.<p>Medium</p> <p>Given an integer array <code>nums</code>, find a contiguous non-empty subarray within the array that has the largest product, and return <em>the product</em>.</p> <p>It is <strong>guaranteed</strong> that the answer will fit in a <strong>32-bit</strong> integer.</p> <p>A <strong>subarray</strong> is a contiguous subsequence of the array.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,3,-2,4]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> [2,3] has the largest product 6.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [-2,0,-1]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> The result cannot be 2, because [-2,-1] is not a subarray.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li> <li><code>-10 <= nums[i] <= 10</code></li> <li>The product of any prefix or suffix of <code>nums</code> is <strong>guaranteed</strong> to fit in a <strong>32-bit</strong> integer.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxProduct

      public int maxProduct(int[] arr)