leetcode 643[easy]--Maximum Average Subarray I
来源:互联网 发布:everspace mac 编辑:程序博客网 时间:2024/05/29 03:13
难度:easy
Given an array consisting of n
integers, find the contiguous subarray of given length k
that has the maximum average value. And you need to output the maximum average value.
Example 1:
Input: [1,12,-5,-6,50,3], k = 4Output: 12.75Explanation: Maximum average is (12-5-6+50)/4 = 51/4 = 12.75
Note:
- 1 <=
k
<=n
<= 30,000. - Elements of the given array will be in the range [-10,000, 10,000].
思路:求给定list里面一段长度为K的片段,使得该片段的具有最大平均值。
遍历全表,找到所有可能的长度为K的片段,求其最大平均值。
关于ans的初始值设定,开始设为0,或者None 均为错误,于是设置为第一个K片段的平均值。
阅读全文
0 0
- leetcode 643[easy]--Maximum Average Subarray I
- LeetCode-Easy-Java-Maximum Average Subarray I
- Leetcode 643 Maximum Average Subarray I
- LeetCode 643 Maximum Average Subarray I
- Leetcode 643 Maximum Average Subarray I
- leetcode 643 Maximum Average Subarray I
- LeetCode.643 Maximum Average Subarray I
- leetcode[Maximum Average Subarray I]
- leetCode-Maximum Average Subarray I
- 643 Maximum Average Subarray I
- LeetCode 643. Maximum Average Subarray I
- [LeetCode]643. Maximum Average Subarray I
- [LeetCode] 643. Maximum Average Subarray I
- LeetCode刷题【Array】 Maximum Average Subarray I
- LeetCode 643. Maximum Average Subarray I
- leetcode 643. Maximum Average Subarray I
- [LeetCode]643. Maximum Average Subarray I
- leetcode 643. Maximum Average Subarray I
- 文章标题
- EasyPlayer RTSP Windows播放器D3D,GDI的几种渲染方式的选择区别
- ISCSI
- Ubuntu下root账户无法使用xshell远程连接解决方法总结
- 简单使用style实现沉浸式状态栏
- leetcode 643[easy]--Maximum Average Subarray I
- 大数据处理决策帆软FineBI4.0.170807最新版完美破解无限用户支持手机APP
- 阿里云新手必看文章-如何领取阿里云优惠券
- linux下使用libusb获取系统usb设备具体信息
- TextView水平轮播(流水灯效果)
- IDEA 2017.3破解
- RedisDemoIncre
- c++stl vector源码简析
- 三国人物-黄月英