public int maxProduct1(int[] A) {
        int maxEnding = A[0];
        int minEnding = A[0];
        int max = A[0];
        for(int i = 1; i < A.length; i++){
            int tmpMax = maxEnding * A[i];
            int tmpMin = minEnding * A[i];
            maxEnding = Math.max(A[i], Math.max(tmpMax, tmpMin));
            minEnding = Math.min(A[i], Math.min(tmpMax, tmpMin));
            if(maxEnding > max) max = maxEnding;
        }
        return max;
    }