- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution643.java
More file actions
Latest commit
executable file
·23 lines (21 loc) · 641 Bytes
/
Copy pathSolution643.java
File metadata and controls
executable file
·23 lines (21 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Created by slade on 2019/6/25.
*/
publicclassSolution643 {
publicdoublefindMaxAverage(int[] nums, intk) {
intsumAns = Integer.MIN_VALUE;
for (inti = 0; i < nums.length - (k - 1); i++) {
inttmpAns = 0;
for (intj = i; j < i + k; j++) {
tmpAns += nums[j];
}
if (tmpAns > sumAns) sumAns = tmpAns;
}
returnsumAns / (k*1.0);
}
publicstaticvoidmain(String[] args) {
Solution643s = newSolution643();
int[] nums = {1, 12, -5, -6, 50, 3};
System.out.println(s.findMaxAverage(nums, 4));
}
}