Open fockspaces opened 1 year ago
GPT improve:
class Solution:
def findMaxAverage(self, nums: List[int], k: int) -> float:
cur_sum = sum(nums[:k])
ans = cur_sum
for i in range(k, len(nums)):
cur_sum = cur_sum - nums[i - k] + nums[i]
ans = max(ans, cur_sum)
return ans / k