## 28. 实现 strStr()

`class Solution {    public int strStr(String haystack, String needle) {        if(needle.length() == 0) return 0;        int[] next = new int[needle.length()];        getNext(next,needle);        int j = 0;        for(int i = 0;i < haystack.length();i++){            while(j > 0 && haystack.charAt(i) != needle.charAt(j)){                j = next[j - 1];            }            if(haystack.charAt(i) == needle.charAt(j)) j++;            if(needle.length() == j){                return i - j + 1;            }        }        return -1;    }    void getNext(int[] next, String needle){        int j = 0;        next[0] = j;        for(int i = 1;i < needle.length();i++){            while(j > 0 && needle.charAt(i) != needle.charAt(j)){                j = next[j - 1];            }            if(needle.charAt(i) == needle.charAt(j)){                j++;            }            next[i] = j;        }    }}`

## 459.重复的子字符串

`class Solution {    public boolean repeatedSubstringPattern(String s) {        String t = s + s;        StringBuilder sb = new StringBuilder(t);        sb.deleteCharAt(0);        sb.deleteCharAt(sb.length() - 1);        System.out.println(sb.toString());        return sb.toString().contains(s);    }}`

`class Solution {    public boolean repeatedSubstringPattern(String s) {        int len = s.length();        char[] ch = s.toCharArray();        int[] next = new int[len];        int j = 0;        for(int i = 1;i < s.length();i++){            while(j > 0 && ch[i] != ch[j]){                j = next[j - 1];            }            if(ch[i] == ch[j]) j++;            next[i] = j;        }        // 最后判断是否是重复的子字符串        if(next[len - 1] > 0 && (len % (len - next[len - 1])) == 0) {            return true;        }        return false;    }}`