알고리즘/LeetCode
LeetCode 풀이 - 1588. Sum of All Odd Length Subarrays
앤테바
2021. 10. 25. 07:32
반응형
1588. Sum of All Odd Length Subarrays
문제)
솔루션1)
class Solution:
def sumOddLengthSubarrays(self, arr: List[int]) -> int:
res = 0
n = len(arr)
for j in range(1, len(arr)+1, 2):
for i in range(n - j + 1):
res += sum(arr[i:i+j])
return res
반응형