方法1:用一个26个长度的int数组表示p串字符出现的次数(map也行,大多数是用map的),从时间考虑的话用int数组,然后窗口的i,j指针指向第一个元素,j向右走,用一个计数器标记如果map中元素用了
class Solution {
List<Integer> res=new ArrayList();
public List<Integer> findAnagrams(String s, String p) {
char[] chs=s.toCharArray();
char[] chp=p.toCharArray();
int[] help=new int[26];
for(char c:chp){
help[c-'a']++;
}
int i=0;
int j=0;
int count=0;
while(j<chs.length){
//进来就对help进行减一,如果此时大于等于0,表示我再一次加进来了p中没用的,如果小于0,表示垃圾元素
help[chs[j]-'a']--;
if(help[chs[j]-'a']>=0){
count++;
}
if(j-i+1>chp.length){
// i++;
//表示从此开始每次i,j同步走一步了。
//如果弹出的i