my pretty easy java solution


  • 0
    L
    public class Solution {
        public double findMaxAverage(int[] nums, int k) {
            int max = 0;
            for (int i = 0; i < k; i++) max += nums[i];
            for (int i = 0, j = k, temp = max; i < nums.length - k; i++, j++) {
                temp += nums[j] - nums[i];
                max = Math.max(temp, max);
            }
            return (double)max / k;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.