python借助队列存储移动窗口内的下标,时间复杂度O(n)
DNA序列
http://www.nowcoder.com/questionTerminal/e8480ed7501640709354db1cc4ffd42a
while True: try: s = input().strip() k = int(input()) queue = [] for i in range(k): if s[i] in 'CG': queue.append(i) max_ratio = len(queue) res = s[:k] for i in range(k, len(s)): if s[i] in 'CG': queue.append(i) if queue[0] <= i-k: queue.pop(0) if len(queue) > max_ratio: max_ratio = len(queue) res = s[i-k+1:i+1] print(res) except: break