public int maxProduct(int[] nums) {
        if (nums.length == 0)
            return 0;
        if (nums.length == 1)
            return nums[0];
        int max = nums[0];
        int[] positive = new int[nums.length];
        positive[0] = nums[0];
        int[] negative = new int[nums.length];
        negative[0] = nums[0];
        for (int i = 1; i < nums.length; ++i) {
            if (nums[i] < 0) {
                positive[i] = Math.max(negative[i - 1] * nums[i], nums[i]);
                negative[i] = Math.min(positive[i - 1] * nums[i], nums[i]);
            } else {
                positive[i] = Math.max(positive[i - 1] * nums[i], nums[i]);
                negative[i] = Math.min(negative[i - 1] * nums[i], nums[i]);
            }
            max = Math.max(max, positive[i]);
        }
        return max;
    }