← 返回 oracle 的题目列表Maximum Product Subarray in O(n) Time
类型:online_judge
oracle
Given an integer array, find the contiguous subarray within an array (containing at least one number) which has the largest product. Your algorithm's time complexity must be O(n).
Input
An integer array nums where 1 <= nums.length <= 2 * 10^4, -10 <= nums[i] <= 10.
Output
Return an integer that represents the maximum product of the contiguous subarray.
Example
Input: [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.
Input: [-2,0,-1]
Output: 0
Explanation: The answer cannot be 2, because [-2,-1] is not a subarray.
Example
Input
2
[2,3,-2,4]