题解 | #DNA序列#

DNA序列

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String sequence = sc.nextLine();
            int n = Integer.parseInt(sc.nextLine());
            List<String> gcList = new ArrayList<>();
            int start = 0;
            int end = n;
            while (end <= sequence.length()) {
                String gc = sequence.substring(start, end);
                gcList.add(gc);
                start ++;
                end ++;
            }
            int max = Integer.MIN_VALUE;
            String gcRatio = "";
            for (String gc : gcList) {
                int len = gc.replace("A", "").replace("T", "").length();
                if (len > max) {
                    max = len;
                    gcRatio = gc;
                }
            }
            System.out.println(gcRatio);
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 11:35
程序员小白条:话太多,没实力和学历,差不多回答回答就行了,身份地位不一样
点赞 评论 收藏
分享
风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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