Here is my sliding windows solution written in C++:

```
class Solution {
public:
double findMaxAverage(vector<int>& nums, int k) {
double cur, res = cur = accumulate(nums.begin(), nums.begin() + k, 0.0) / (double) k;
for (int i = k; i < nums.size(); ++i) {
cur = cur - (double) nums[i-k] / k + (double) nums[i] / k;
if (cur > res) res = cur;
}
return res;
}
};
```