题解 | #串的模式匹配#

串的模式匹配

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;
    }
};

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务