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;
}
};

扫描一遍,更新当前和,最大和,最后取走最大和即可

643. Maximum Average Subarray I的更多相关文章

  1. 【Leetcode_easy】643. Maximum Average Subarray I

    problem 643. Maximum Average Subarray I 题意:一定长度的子数组的最大平均值. solution1:计算子数组之后的常用方法是建立累加数组,然后再计算任意一定长度 ...

  2. 643. Maximum Average Subarray I 最大子数组的平均值

    [抄题]: Given an array consisting of n integers, find the contiguous subarray of given length k that h ...

  3. LeetCode 643. Maximum Average Subarray I (最大平均值子数组之一)

    Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...

  4. 643. Maximum Average Subarray

    Given an array consisting of \(n\) integers, find the contiguous subarray of given length \(k\) that ...

  5. [Leetcode]643. Maximum Average Subarray I

    Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...

  6. [LeetCode] 643. Maximum Average Subarray I_Easy tag: Dynamic Programming(Sliding windows)

    Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...

  7. leetcode 643. Maximum Average Subarray I 子数组最大平均数 I

    一.题目大意 https://leetcode.cn/problems/maximum-average-subarray-i/ 给你一个由 n 个元素组成的整数数组 nums 和一个整数 k . 请你 ...

  8. LeetCode 643. 子数组最大平均数 I(Maximum Average Subarray I)

    643. 子数组最大平均数 I 643. Maximum Average Subarray I 题目描述 给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数. LeetCo ...

  9. Maximum Average Subarray II LT644

    Given an array consisting of n integers, find the contiguous subarray whose length is greater than o ...

随机推荐

  1. 5. window.location.href/replace/reload()--页面跳转+替换+刷新

    1.window.location=url; window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面. 一.最外层top跳转页面,适合用于iframe框架集 ...

  2. 【Javascript Demo】遮罩层和百度地图弹出层简单实现

    其实想做的就是显示百度地图的弹出层,现在已经简单实现了.示例和代码如下,点击按钮可以看到效果: 1.示例:   2.代码: <!DOCTYPE html PUBLIC "-//W3C/ ...

  3. c++builder 6 远程调试

    Delphi7环境 一.目标远程机器: 安装服务光盘里有,单独安装,启动,启动后目标机的托盘图标中会出现一个小“虫子”debug的图标 bordbg61.exe D:\Program Files (x ...

  4. Spring MVC 异常处理 - SimpleMappingExceptionResolver

    希望对一些异常统一处理,他将异常类名映射为视图名,即发生异常时使用对应的视图报告异常.

  5. libcurl 不支持https访问

    项目中使用libcurl 访问https的时候会报错,比如:“Unsupported protocol” 或者:“Protocol https not supported or disabled in ...

  6. mongodb基础学习14-mapReduce操作

    mapReduce随着大数据的兴起而流行,相当于传统数据库的group操作,强项在于分布式计算. map:将一组记录的相关信息映射到一个数组 reduce:对map得到的数组数据进行处理得到一个结果 ...

  7. 八月(The Summer is Gone)观后感

    第一次看到这部电影时觉得很亲近,黑白画面,国企改革的背景,浓浓的儿时画面感,原谅我只是一个三十不到的人,可能我比较早熟,对八九十年代还有些记忆,更早以前也通过电视.音乐.书籍等了解过一些,而那些听过又 ...

  8. org.springframework.stereotype 注解

    org.springframework.stereotype 1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访 ...

  9. 关于Application.DoEvents()==转

    记得第一次使用Application.DoEvents()是为了在加载大量数据时能够有一个数据加载的提示,不至于系统出现假死的现象,当时也没有深入的去研究他的原理是怎样的,结果在很多地方都用上了App ...

  10. 【校招面试 之 C/C++】第6题 C++深拷贝与浅拷贝

    1.两个的区别(1)在未定义显示拷贝构造函数的情况下,系统会调用默认的拷贝函数——即浅拷贝,它能够完成成员的一一复制.当数据成员中没有指针时,浅拷贝是可行的: 但当数据成员中有指针时,如果采用简单的浅 ...