输出最长相邻DAN长度

 var readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal:false }); var str = ''; rl.on('line', function(line){   str = line.trim(); // 输出结果  console.log(maxLengthDNA(str));   str = '';
}); function maxLengthDNA(str){ var strarr = str.split(""); var arrLength = 0; var newarrLength = 0; if(str.indexOf('A')!=-1||str.indexOf('T')!=-1||str.indexOf('C')!=-1||str.indexOf('G')!=-1){ newarrLength = 1; var i = 0; for(i;i<strarr.length;i++){ var arr = []; if(strarr[i]=='A'||strarr[i]=='T'||strarr[i]=='C'||strarr[i]=='G'){ arr.push(strarr[i]); for(var j=i+1;j<strarr.length;j++){ if(strarr[j]=='A'||strarr[j]=='T'||strarr[j]=='C'||strarr[j]=='G'){ arr.push(strarr[j]); newarrLength = arr.length; i=j;
                    }else{ if(newarrLength<arrLength){ newarrLength = arrLength;
                        }else{ arrLength = newarrLength;
                        } break;
                    }
                }
            }
        }
    } return newarrLength;
}


全部评论

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务