题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
1.切字符串,2用正则表达式全局搜索找最多CG个数字符串
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let arr = [];
rl.on("line", function (line) {
arr.push(line);
if (arr.length == 2) {
let str = arr[0];
let len = arr[1];
let max = 0
let res ;
for (let index in str) {
let endIndex = parseInt(index) + parseInt(len);
if (endIndex > str.length) {
break;
} else {
let re = /[CG]/g
let subStr = str.substring(index, endIndex);
let count = subStr.match(re).length
if(count > max){
max = count
res = subStr
}
}
}
if(max>0){
console.log(res)
}
}
});
//最高基因