题解 | #DNA序列#

DNA序列

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

const getGCRatio = str => {
  return str.match(/[GC]/g).length / str.length
}
while(str = readline()) {
  const len = ~~readline();
  let i=0;
  let res = {
    v: "",
    gcRatio: 0
  };
  for(let k=len;k<=str.length;k++) {
    const subStr = str.slice(i, k);
    if(/^[ACGT]+$/.test(subStr)) {
      const gcRatio = getGCRatio(subStr);
      if(gcRatio > res.gcRatio) {
        res.v = subStr;
        res.gcRatio = gcRatio;
      }
    }
    i++;
  }
  console.log(res.v);
}
全部评论

相关推荐

鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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