[LeetCode] Maximum Average Subarray I 子数组的最大平均值 Given an array consisting ofnintegers, find the contiguous subarray of given lengthkthat 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.7...
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. 这道题是之前那道Maximum Average Subarray I的拓展,那道题说是要找长度为k的子数组的最大平均值,而这道题要找长度大于等于k的子数组的最大平均值。加了个...
You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B). Return true if it is possible to achieve that and false otherwise. Note that for an array arr, average(arr) is the sum of all the elements ...
Elements of the given array will be in the range [-10,000, 10,000]. 思路:把数组里每 K 个连续 classSolution {publicdoublefindMaxAverage(int[] nums,intk) {doublesum = 0;for(inti = 0; i < k; i++) sum+=nums[i];doublemax =sum;for(inti = 0; i < nums.length - k; i++){...