DNA序列
不用直接去比字符串,可以直接比较长度为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)); } }
本文来自博客园,作者:LeeJuly,转载请注明原文链接:https://www.cnblogs.com/peterleee/p/10855016.html

浙公网安备 33010602011771号