题解 | #DNA序列#

DNA序列

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

package main

import (
	"fmt"
	"strings"
)

func main() {

	str := ""
	n := 0
	fmt.Scan(&str)
	fmt.Scan(&n)
	//记录G 、C 出现最多的 index
	maxIndex := 0
	//记录G 、C 出现最多的个数
	maxCount := 0
	//滑动窗口求解出maxIndex
	for i := 0; i < len(str)-n; i++ {
		tempStr := str[i : i+n]
		count := 0
		count += strings.Count(tempStr, "C")
		count += strings.Count(tempStr, "G")
		if count > maxCount {
			maxCount = count
			maxIndex = i
		}
	}
	//根据 maxIndex输出 子串即可
	fmt.Println(str[maxIndex : maxIndex+n])

}

全部评论

相关推荐

27双非本,最近面试被挂麻了面试官说简历内容太简单了,技术栈要单独一行,各位佬有啥建议吗
LZStarV:项目太简单了,你像用什么开发的技术栈没必要写一句话,按点写就好了;有特色的比如说WebSocket、视频流这种狠狠吹,那就好看多了
点赞 评论 收藏
分享
迷茫的大四🐶:现在是幻想时间查看图片
双非本科的出路是什么?
点赞 评论 收藏
分享
已注销:bro不如吃顿疯狂星期四
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务