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. word 2013 自动保存太慢,下面读条起码3分钟

    该问题有可能是应用干扰或者安全设置问题导致的. 建议您尝试以下方法: 方法一: 尝试使用干净启动来暂时禁用计算机启动时所加载的第三方程序来进一步做测试: 如何在Windows 中执行干净启动步骤 具体 ...

  2. 去除android手机浏览器中, 按住链接出现border的情况

    body{ -moz-user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color:transparent; }

  3. as3的全屏功能的实现主要是舞台stage的displayState属性

    StageDisplayState.NORMAL                                               正常 StageDisplayState.FULL_SCR ...

  4. JSTL-taglib

    JSTL(JSP Standard Tag Lib) 目录: Core Fmt Function SimpleTagSupport(jsp 自定义标签) Tag File Core <%@ ta ...

  5. 3 并发编程-(进程)-join方法

    1.查看当前进程的进程号getpid() 和 其父 进程号 getppid() # 查看进程的pid from multiprocessing import Process import time,o ...

  6. 数组去重的三种方法 es6

    [1,2,3,4,5,6,7,8,9,2,2,3,3,4,1].filter(function(el,index,arr){ return (index === arr.indexOf(el)); } ...

  7. 解决Linux命令行为什么变成-bash-3.2$

    在Linux服务器上创建了一个新用户probe,是这样创建的: [root@localhost home]# groupadd -g 501 probe [root@localhost home]# ...

  8. springboot 使用的配置

    1,控制台打印sql logging: level: com.sdyy.test.mapper: debug 2,开启驼峰命名 mybatis.configuration.map-underscore ...

  9. layoutSubviews相关总结

    ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ------- - (void)layoutSubview ...

  10. 文件和Variant的转换

    function FileToVariant(FileName: String): OleVariant; var   AStream: TFileStream;   MyBuffer: Pointe ...