Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int sumOddLengthSubarrays(vector<int>& arr) {
- int sum=0;
- int n=arr.size();
- for(int i=0;i<n;i++)
- {
- int count= ((i+1)*(n-i) +1)/2;
- sum+= count* arr[i];
- }
- return sum;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment