public class StringMatch {
/**
* 暴力匹配法
*/
private static int StringMa(String s,String p){
int SLen = s.length();
int PLen = p.length();
int i= 0,j=0;
while(i<SLen && j<PLen){
if(s.charAt(i) == p.charAt(j)){
i++;
j++;
}else{
i = i-j+1; //此处属于位置的回溯
j=0;
}
}
if(j==PLen){
return i-j;
}else{
return -1;
}
}
}
有一个文本串S和一个模式串P,要查找P在S中的位置—暴力破解法
猜你喜欢
转载自blog.csdn.net/qq_39536716/article/details/83046738
今日推荐
周排行