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 }}
力扣算法之《438. 找到字符串中所有字母异位词》(附:第一次遇上滑块问题,参照官网解决方法手打代码 ????)class Solution { public List<Integer> findAnagrams(String s, String p) { // type the following code follow the solution of official website of Likou if(s.length() < p.le