题解 | #串的模式匹配#
串的模式匹配
http://www.nowcoder.com/practice/084b6cb2ca934d7daad55355b4445f8a
class StringPattern {
public:
int findAppearance(string A, int lena, string B, int lenb) {
// write code here
for(int i=0;i<lena;i++){
if(A[i]==B[0]){ //找到首字母了
if(lenb==1) return i;
for(int j =1;j<lenb;j++){ //继续寻找下面的
if(A[i+j]!=B[j]){
break;
}
if(j==lenb-1){
return i;
}
}
}
}
return -1;
}
};


