1588. Sum of All Odd Length Subarrays

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1588

class Solution:
    def sumOddLengthSubarrays(self, arr: List[int]) -> int:
        res, n = 0, len(arr)
        for i in range(n):
            s = 0
            for j in range(i, n):
                s += arr[j]
                if (j - i + 1) & 1:
                    res += s
        return res