0643. 子数组最大平均数 I #243
Replies: 1 comment
-
|
这样感觉就是单个指针了,但是感觉更方便。 class Solution:
def findMaxAverage(self, nums: List[int], k: int) -> float:
right = k
max_sum = sum(nums[:right])
avg = max_sum
while right < len(nums):
avg = avg + nums[right] - nums[right - k]
max_sum=max(max_sum,avg)
right += 1
return max_sum/k |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
0643. 子数组最大平均数 I
--- 0643. 子数组最大平均数 I 标签:数组、滑动窗口 难度:简单 题目链接 0643. 子数组最大平均数 I - 力扣 题目大意 描述:给定一个由 n 个元素组成的整数数组 nums 和一个整数 k。 要求:找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。 说明: 任何误差小于 10−5 的答案都将被视为正确答案。 n==num...
https://algo.itcharge.cn/solutions/0600-0699/maximum-average-subarray-i/
Beta Was this translation helpful? Give feedback.
All reactions