Skip to content

Commit c2b9d29

Browse files
Create 1588. Sum of All Odd Length Subarrays.cpp
1 parent fcbc368 commit c2b9d29

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int sumOddLengthSubarrays(vector<int>& arr) {
4+
int sum=0;
5+
int res=0;
6+
vector<int> v;
7+
for(int i=0;i<arr.size();i++)
8+
{
9+
v.clear();
10+
sum=0;
11+
for(int j=i;j<arr.size();j++)
12+
{
13+
v.push_back(arr[j]);
14+
sum+=arr[j];
15+
16+
if(v.size()%2!=0) res+=sum;
17+
}
18+
}
19+
return res;
20+
}
21+
};

0 commit comments

Comments
 (0)