题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
function getMaxRatioSubStr(str, num) { let ratio = 0; let maxSubStr = ''; let count = 0; const base = ['G', 'C']; while (str.length) { let temp = str.substring(0, num); let tempArr = temp.split(''); tempArr.forEach(char => { count += base.includes(char) ? 1 : 0; }); if ((count / num) > ratio) { ratio = count / num; maxSubStr = temp; } str = str.substr(1); count = 0; } return maxSubStr; } while (line = readline()) { const substrNum = readline(); print(getMaxRatioSubStr(line, parseInt(substrNum, 10))); }