Skip to content

Commit 546ea3a

Browse files
Create Sum of Variable Length Subarrays.cpp
1 parent 9a4a230 commit 546ea3a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sum of Variable Length Subarrays.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int subarraySum(vector<int>& nums) {
4+
5+
int sum = 0;
6+
for(int i = 0 ; i<nums.size(); i++){
7+
int start = max(0 , i- nums[i]);
8+
int currSum = 0;
9+
for(int j = start; j<=i; j++){
10+
currSum += nums[j];
11+
}
12+
sum += currSum;
13+
}
14+
15+
return sum;
16+
}
17+
};

0 commit comments

Comments
 (0)