java朴素解法
DNA序列
http://www.nowcoder.com/questionTerminal/e8480ed7501640709354db1cc4ffd42a
很朴素的解法
感觉也没有别的
复杂度O(NK)
import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String in; while((in = br.readLine())!=null){ int w= Integer.parseInt(br.readLine());//输入窗口大小 System.out.println(getString(in,w)); } } public static String getString(String in,int w){ int maxLen=0; String res=""; for(int i=0;i<in.length()-w+1;i++){ int tmp=countSubString(in.substring(i,i+w)); if(tmp>maxLen){ maxLen=tmp; res=in.substring(i,i+w); } } return res; } public static int countSubString(String in){ int count=0; for(int i=0;i<in.length();i++){ if(in.charAt(i)=='C'||in.charAt(i)=='G') count++; } return count; } }