package leetcode;import java.util.Arrays;public class ImplementStrStr { public int strStr(String haystack, String needle) { if(haystack==null||needle==null)return -1; return haystack.indexOf(needle); } public int[] getNext(String str){ int []preFix=new int[str.length()]; int i=0; for(i=1;i0&&haystack.charAt(i)!=needle.charAt(j)){ j = pre[j-1]; } if(haystack.charAt(i)==needle.charAt(j)){ j++; } i++; if(j==needLength){ return i-j; } } return -1; } public int[] next(String param){ int[] next=new int[param.length()]; next[0]=-1; int length=param.length(); int i=0; int j=-1; while(i