-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0643 [E] Maximum Average Subarray I
Code with Senpai edited this page Oct 21, 2022
·
2 revisions
class Solution:
def findMaxAverage(self, nums: List[int], k: int) -> float:
max_total = total = sum(nums[0:k]) # first window up to len k
for r in range(k, len(nums)): # rest windows from k to end
total += nums[r] # add right
l = r - k
total -= nums[l] # subtract left
max_total = max(max_total, total)
return max_total / k
footer