Problem
Given an integer array nums, find the contiguous, non-empty subarray whose elements have the largest product, and return that product.
Example 1
- Input
- nums = [2, 3, -2, 4]
- Output
- 6
- Why
- [2, 3]
Example 2
- Input
- nums = [-2, 0, -1]
- Output
- 0
- Why
- [0]
Example 3
- Input
- nums = [-2, 3, -4]
- Output
- 24
- Why
- the whole array: two negatives cancel
Constraints
1 <= nums.length <= 2 * 10^4-10 <= nums[i] <= 10The product of any subarray fits in a 32-bit integer.