Skip to content

Commit 33b3867

Browse files
aQuaaQua
aQua
authored and
aQua
committed
643 finish
1 parent 9e7a370 commit 33b3867

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Algorithms/0643.maximum-average-subarray-i/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Note:
1414
Elements of the given array will be in the range [-10,000, 10,000].
1515

1616
## 解题思路
17-
17+
见程序
1818

1919
## 总结
2020

Algorithms/0643.maximum-average-subarray-i/maximum-average-subarray-i.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package Problem0643
22

33
func findMaxAverage(nums []int, k int) float64 {
44
temp := 0
5-
for j := 0; j < k; j++ {
6-
temp += nums[j]
5+
for i := 0; i < k; i++ {
6+
temp += nums[i]
77
}
88

99
max := temp
1010

11-
for i, j := 0, k; j < len(nums); i, j = i+1, j+1 {
12-
temp = temp - nums[i] + nums[j]
11+
for i := k; i < len(nums); i++ {
12+
temp = temp - nums[i-k] + nums[i]
1313

1414
if max < temp {
1515
max = temp

0 commit comments

Comments
 (0)