题解 | #平均数为k的最长连续子数组#
平均数为k的最长连续子数组
https://www.nowcoder.com/practice/2e47f99735584ac5ba30d75ac14d6524
from itertools import accumulate n,k=map(int,input().split()) number=list(map(int,input().split())) for i in range(n): number[i]-=k number1=list(accumulate(number,initial=0)) dict1={} count=-1 for index,value in enumerate(number1): if value not in dict1: dict1[value]=index else: count=max(count,index-dict1[value]) print(count)
借鉴(copy)了高手的代码,思路真的厉害。