644 Maximum Average Subarray II
1. Question
Given an array consisting ofn
integers, find the contiguous subarray whose length is greater than or equal tok
that has the maximum average value. And you need to output the maximum average value.
Example 1:
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.
2. Implementation
(1) Brute Force
(2) Binary Search
3. Time & Space Complexity
Brute Force: 时间复杂度O(n^2), 空间复杂度O(1)
Binary Search: 时间复杂度O(n * log(max - min)), 空间复杂度O(1)
Last updated