LeetCode] 644.Maximum Average Subarray II
LeetCode 644. Maximum Average Subarray II lintcode 671 Given an array consisting of n integers, find the contiguous subarray whose length is greater than or equal to 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 = 4 Output: 12.75 Explanation: when length is 5, maximum average value is 10.8, when length is 6, maximum average value is 9.16667. Thus return 12.75. Note: 1 <= k <= n <= 10,000. Elements of the given array will be in range [-10,000, 10,000]. The answer with the calculation error less than 10 -5 will be accepted. 题目大意: 给定包含n个整数的数组,寻找长度大于等于k的连续子数组的平均值的最大值。 没有买leetcode,所以复制粘贴了题目,这道题看起来跟 他的兄弟 差不多,但是实际上差很多。。。 lintcode 671 这个一模一样的就是hint和限制条件没有。所以可以用这个来测。 这个解释的很详细 https://leetcode.com/articles/maximum-average-subarray-ii/ 这个也很好 http://blog.csdn.net/zjucor/article/details/75199933 我开始用的是暴力解法,就是把它兄弟重复很多遍,当然,超时哦。然后就不知道怎么办了,看的答案,看完恍然大悟,原来里面有套路: 1. 只要满足