DNA序列

 

https://www.nowcoder.com/practice/ab900f183e054c6d8769f2df977223b5?tpId=90&tqId=30789&tPage=1&rp=1&ru=/ta/2018test&qru=/ta/2018test/question-ranking

不用直接去比字符串,可以直接比较长度为n的长度的个数和4^n大小

import java.util.*;
public class Main{
    public static int getDna(String str) {
        int n=str.length();
        for(int i=1;i<=n;i++) {
            HashSet<String> set = new HashSet<>();
            for(int j=0;j<=n-i;j++) set.add(str.substring(j, j+i));
            if(set.size()<Math.pow(4, i)) return i;
        }
        return n;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();
        System.out.println(Main.getDna(input));
    }
}

 

posted @ 2019-05-13 09:50  LeeJuly  阅读(374)  评论(0)    收藏  举报