class Solution {
public:
double findMaxAverage(vector<int>& nums, int k) {
int n = nums.size();
int temp = 0;
for(int i = 0; i < k; ++i){
temp += nums[i];
}
int sum = temp;
for(int i = k; i < n; ++i){
temp = temp - nums[i - k] + nums[i];
sum = max(sum,temp);
}
return 1.0 * sum / k;
}
};
LeetCode 643. 子数组最大平均数 I
最新推荐文章于 2024-08-16 10:27:08 发布