题解 | #连续子数组的最大乘积#

连续子数组的最大乘积

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);
    }
}
全部评论

相关推荐

合适才能收到offe...:招聘上写这些态度傲慢的就别继续招呼了,你会发现hr和面试官挺神的,本来求职艰难就可能影响一些心态了,你去这种公司面试的话,整个心态会炸的。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务