Skip to content

Commit 95b60af

Browse files
author
Dream
committed
[update] 643
1 parent 1690ae7 commit 95b60af

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
|655|[Print Binary Tree](https://leetcode.com/problems/print-binary-tree/) | |Medium|
8080
|652|[Find Duplicate Subtrees](https://leetcode.com/problems/find-duplicate-subtrees/) | |Medium|
8181
|647|[Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) | |Medium|
82-
|643|[Maximum Average Subarray I](https://leetcode.com/problems/maximum-average-subarray-i/description/) | |Easy|
82+
|643|[Maximum Average Subarray I](https://leetcode.com/problems/maximum-average-subarray-i/description/) | [Java_dream](./algorithms/maximumAverageSubarrayI/MaximumAverageSubarrayI.java) |Easy|
8383
|628|[Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/) | |Easy|
8484
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Medium|
8585
|626|[Exchange Seats](https://leetcode.com/problems/exchange-seats/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @author Dream
3+
*/
4+
public class MaximumAverageSubarrayI {
5+
public double findMaxAverage(int[] nums, int k) {
6+
int sum = 0, max;
7+
for (int i = 0; i < k; i++) {
8+
sum += nums[i];
9+
}
10+
max = sum;
11+
for (int i = k; i < nums.length; i++) {
12+
sum = sum - nums[i - k] + nums[i];
13+
max = Math.max(max, sum);
14+
}
15+
return (double)max/k;
16+
}
17+
}

0 commit comments

Comments
 (0)