static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
double findMaxAverage(vector<int>& nums, int k)
{
int sz=nums.size();
double maxsum=0.0;
double cursum=0.0;
for(int i=;i<k;i++)
cursum+=nums[i];
maxsum=cursum;
for(int j=k;j<sz;j++)
{
cursum=cursum-nums[j-k]+nums[j];
maxsum=max(cursum,maxsum);
}
return maxsum/k;
}
};
扫描一遍,更新当前和,最大和,最后取走最大和即可