题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { const DNA = await readline(); const k = parseInt(await readline()); let cnt = 0,max = 0, start = 0; for(let i = 0; i < k; i++){ if(DNA.charAt(i) === "C" || DNA.charAt(i) === "G") cnt ++; } max = cnt; for(let i = 1; i < DNA.length - k; i++){ if(DNA.charAt(i-1) === "C" || DNA.charAt(i-1) === "G") cnt--; if(DNA.charAt(i+k-1) === "C" || DNA.charAt(i+k-1) === "G") cnt++; if(cnt > max){ max = cnt; start = i; } } console.log(DNA.slice(start,start+k)); }()