class Solution {
/**
思路:
滑动窗口
窗口大小为 k 的最大和
找到后除以 k 就是答案
*/
public double findMaxAverage(int[] nums, int k) {
int sum = 0;
for (int i = 0; i < k; i++) {
sum += nums[i];
}
int ans = sum;
int cur = sum;
for (int i = k; i < nums.length; i++) {
cur = cur - nums[i - k] + nums[i];
ans = Math.max(ans, cur);
}
return ans * 1.0 / k;
}
}