I have a deep understanding of this problem, in the prior description of the code at run time only 34% pass the test, and the wrong reason I attributed it to the system error
(。。。。。。。 )
The answer to my output is wrong ....
I used violence all over the calendar, and every one of them could be compared. Of course I looked at others and there was a dichotomy, but I didn't understand. My code is as follows:
Package com.test;
public class Zuidapingjunzishuzu {public
static void Main (string[] args) {
//int arr[] = {1,12,-5,-6,50,3};
int arr[] = { -1,-2,-3,-100,-1,-50};
Double A = Maxaverage (arr,4);
System.out.println (a);
}
/**
* asks for a maximum subarray whose sub-arrays are of the length k
*
/public static double Maxaverage (int[] nums, int k) {
int len = nums.length; //Array length
int count = 1; Array pointer
double maxsum = 0; The AND/* * of the maximum subarray
first assigns the sum of the first k numbers to Maxsun */for
(int i = 0; i < K; i++) {
maxsum + nums[i];
}
/* * Main algorithm *
/while (Count <= len-k) {
//temp resets every cycle, so create a
double temp = 0 here;
Sum each k number from the second number and assign to Temo for
(int j = 0; J < K; J + +) {
temp + = Nums[count+j];
}
Compare the values of temp and maxsun, remembering that each counter moves backwards one
if (temp > Maxsum) {
maxsum = temp;
count++;
} else{
count++;
}
}
return maxsum/k;
}
}