package leetcode;

/**
 * https://leetcode.com/problems/sum-of-all-odd-length-subarrays/
 */
public class Problem1588 {
    public int sumOddLengthSubarrays(int[] arr) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1588 prob = new Problem1588();
        System.out.println(prob.sumOddLengthSubarrays(new int[]{1,4,2,5,3})); // 58
        System.out.println(prob.sumOddLengthSubarrays(new int[]{1,2})); // 3
        System.out.println(prob.sumOddLengthSubarrays(new int[]{10,11,12})); // 66
    }
}

@@ -175,375 +175,598 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1588 prob = new Problem1588();%0A        System.out.println(prob.sumOddLengthSubarrays(new int%5B%5D%7B1,4,2,5,3%7D)); // 58%0A        System.out.println(prob.sumOddLengthSubarrays(new int%5B%5D%7B1,2%7D)); // 3%0A        System.out.println(prob.sumOddLengthSubarrays(new int%5B%5D%7B10,11,12%7D)); // 66
+int%5B%5D prefixSum = new int%5Barr.length%5D;%0A        for (int i = 0; i %3C arr.length; i++) %7B%0A            if (i == 0) %7B%0A                prefixSum%5Bi%5D = arr%5Bi%5D;%0A            %7D else %7B%0A                prefixSum%5Bi%5D = prefixSum%5Bi - 1%5D + arr%5Bi%5D;%0A            %7D%0A        %7D%0A        int answer = 0;%0A        for (int len = 1; len %3C= arr.length; len += 2) %7B%0A            for (int i = 0; i %3C arr.length; i++) %7B%0A                if (i + len - 1 %3C arr.length) %7B%0A                    answer += prefixSum%5Bi + len - 1%5D - (i - 1 %3E= 0 ? prefixSum%5Bi - 1%5D : 0);%0A                %7D%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1588