技巧:采用滑动窗口方法,首数值更新尾数值
实现:
def max_continue_avg(li, k): first_sum = 0 for i in range(k): first_sum += li[i] res = first_sum for j in range(k, len(li)): first_sum = first_sum + li[j] - li[j-k] res = max(first_sum, res) return res / k
返回:10.0