题解 | #DNA序列#

DNA序列

http://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a

def run(seq, n):
    pre = seq[0:n].count('C') + seq[0:n].count('G')
    maxcg = pre
    res = seq[0:n]
    for i in range(1, len(seq)-n):
        tmp = pre
        if seq[i-1] in ["C", "G"]:
            tmp = tmp-1
        if seq[i+n-1] in ["C", "G"]:
            tmp += 1
        if tmp > maxcg:
            res = seq[i:i+n]
            maxcg = tmp
        pre = tmp
    return res

seq = input().strip()
n = int(input())

print(run(seq, n))
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务