Maximum Average Subarray



easy to understand Java Solution
class Solution { public double findMaxAverage(int[] nums, int k) { if (nums.length == 1)return (double)nums[0]; double max = Integer.MIN_VALUE; loop1: for (int i=0;i<nums.length;i++){ int sum = nums[i]; for (int j=i+1;j<i+k;j++){ if (j>=nums.length)break loop1; sum = sum + nums[j]; } double average = (double)sum/k; if (average>max){ max = average; } } return max; } }