【发布时间】:2015-04-18 04:51:36
【问题描述】:
我编写这段代码是为了在大文本中搜索小文本。到目前为止,它非常缓慢。我该如何优化它?请帮我优化这段代码。
public class St {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader b1=new BufferedReader(new InputStreamReader(System.in));
String s=b1.readLine();
String t=b1.readLine();
String news = null;
//double u=t.hashCode();
//double q=s.hashCode();
//double x;
//.out.print(u+"\n"+q);
int x=t.length();
int y=s.length();
for(int i=0;i<y-x-1;i++){
//news=s.substring(i, i+t.length());
//x=news.hashCode();
//System.out.println(news);
if(t.equals(s.substring(i, i+x))){
System.out.println(i);
}
}
}
}
【问题讨论】:
标签: java string algorithm optimization