643. Maximum Average Subarray I Easy
1/**
2 * [643] Maximum Average Subarray I
3 *
4 * You are given an integer array nums consisting of n elements, and an integer k.
5 * Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10^-5 will be accepted.
6 *
7 * Example 1:
8 *
9 * Input: nums = [1,12,-5,-6,50,3], k = 4
10 * Output: 12.75000
11 * Explanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75
12 *
13 * Example 2:
14 *
15 * Input: nums = [5], k = 1
16 * Output: 5.00000
17 *
18 *
19 * Constraints:
20 *
21 * n == nums.length
22 * 1 <= k <= n <= 10^5
23 * -10^4 <= nums[i] <= 10^4
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/maximum-average-subarray-i/
29// discuss: https://leetcode.com/problems/maximum-average-subarray-i/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn find_max_average(nums: Vec<i32>, k: i32) -> f64 {
35 0f64
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_643() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.