Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
The order of output does not matter.
效率比较低,需要想一下较优解
public List<Integer> findAnagrams(String s, String p) {
List<Integer> res = new ArrayList<>();
int pLen = p.length();
char[] pChar = p.toCharArray();
Arrays.sort(pChar);
for (int i = 0; i <= s.length()-pLen; i ++) {
char[] sSubChar = s.substring(i, i+pLen).toCharArray();
Arrays.sort(sSubChar);
if (Arrays.equals(pChar, sSubChar)) {
res.add(i);
}
}
return res;
}