题解 | #连续子数组的最大乘积#
连续子数组的最大乘积
http://www.nowcoder.com/practice/fd8c819c07c9493887bfac8549c119f4
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(new BufferedInputStream(System.in));
int n = scan.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++)
nums[i] = scan.nextInt();
int preMax = 1;
int preMin = 1;
int res = (int)-1e9;
for (int num: nums) {
int a = preMax * num, b = preMin * num;
preMax = Math.max(Math.max(a, b), num);
preMin = Math.min(Math.min(a, b), num);
res = Math.max(preMax, res);
}
System.out.println(res);
}
}