阅读背景:

字符串模式匹配(KMP)

来源:互联网 

1、简单模式匹配

    public static int findIndex(String s, String t) {
        int index = 0;
        char[] sChars = s.toCharArray();
        char[] tChars = t.toCharArray();
        int i = 0, j = 0;
        while (i < sChars.length && j < t.length()) {
            if(sChars[i] == tChars[j]) {
                i++;
                j++;
            } else {
                i = i - j + 1;
                j = 0;
            }
        }
        if(j == tChars.length) {
            index = i - j;
        } else {
            index = -1;
        }
        return index;
    }    public static int fin



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: