1588. Sum of All Odd Length Subarrays
On This Page
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