classSolution{publicList<Integer>findAnagrams(String s,String p){// type the following code follow the solution of official website of Likou if(s.length()< p.length())returnnewArrayList<Integer>();List<Integer> ans =newArrayList<Integer>();int slen = s.length(), plen = p.length();int[]ss =newint[26];int[]pp =newint[26];// initial ss and ppfor(int i=0; i < plen;++i){
ss[s.charAt(i)-'a']++;
pp[p.charAt(i)-'a']++;}if(Arrays.equals(ss, pp)){
ans.add(0);}// start to slidefor(int i =0; i < slen - plen;++i){
ss[s.charAt(i)-'a']--;// recover the front state
ss[s.charAt(i+plen)-'a']++;// update the next state// slide successif(Arrays.equals(ss, pp)){
ans.add(i+1);}}return ans;// type the following code follow the solution of official website of Likou }}