Skip to content

Commit 42dbc42

Browse files
committed
Runtime: 487 ms (Top 9.36%) | Memory: 130 MB (Top 70.74%)
1 parent f432074 commit 42dbc42

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1+
// Runtime: 487 ms (Top 9.36%) | Memory: 130 MB (Top 70.74%)
12
class Solution {
23
public:
34
vector<int> getAverages(vector<int>& nums, int k) {
4-
5+
56
int n = nums.size();
67
vector<int> ans(n , -1);
7-
8+
89
if(2 * k + 1 > n) return ans;
9-
10-
10+
1111
// Simple Sliding Window
12-
12+
1313
long long int sum = 0;
14-
14+
1515
// Take a window of size 2 * k + 1
1616
for(int i =0 ; i < 2 * k + 1 ; i++) {
1717
sum += nums[i];
1818
}
19-
19+
2020
ans[k] = sum / (2 * k + 1);
21-
21+
2222
// Then slide it untill the end of the window reaches at the end
23-
23+
2424
for(int i = 2 * k + 1 , j = k + 1, s = 0; i < n ; i++ , j++, s++) {
25-
25+
2626
sum += nums[i];
2727
sum -= nums[s];
2828
ans[j] = sum /(2 * k + 1);
29-
29+
3030
}
31-
31+
3232
return ans;
3333
}
34-
};
34+
};

0 commit comments

Comments
 (0)