Given an array of integers numbers
, determine the subarray that has the highest product and return that product.
A subarray is a contiguous segment of an array where all elements are taken from consecutive indices, preserving their order, such as [2, 3]
in [1, 2, 3, 4]
, while non-contiguous selections like [1, 3]
are not valid subarray.
numbers: number[]
: An array of integersnumbers
is guaranteed to fit in a 32-bit integerInput: numbers = [1,2,-3,5,1]Output: 5Explanation: The subarray [5, 1] has the largest product i.e 5.
Input: numbers = [9]Output: 9Explanation: The single-element subarray [9] has the largest product i.e 9.
Input: numbers = [1,2,0,-1,8,-4]Output: 32Explanation: The subarray [-1, 8, -4] has the largest product i.e 32.
numbers.length
<= 1000numbers[i]
<= 10Given an array of integers numbers
, determine the subarray that has the highest product and return that product.
A subarray is a contiguous segment of an array where all elements are taken from consecutive indices, preserving their order, such as [2, 3]
in [1, 2, 3, 4]
, while non-contiguous selections like [1, 3]
are not valid subarray.
numbers: number[]
: An array of integersnumbers
is guaranteed to fit in a 32-bit integerInput: numbers = [1,2,-3,5,1]Output: 5Explanation: The subarray [5, 1] has the largest product i.e 5.
Input: numbers = [9]Output: 9Explanation: The single-element subarray [9] has the largest product i.e 9.
Input: numbers = [1,2,0,-1,8,-4]Output: 32Explanation: The subarray [-1, 8, -4] has the largest product i.e 32.
numbers.length
<= 1000numbers[i]
<= 10console.log()
语句将显示在此处。