题目链接
字符串哈希 对哈希的方法还是有点理解的不好
public List<Integer> findAnagrams(String s, String p) {
int phash = gethash(p);
int plen = p.length();
int slen = s.length();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < slen - plen + 1; i++) {
int ss = gethash(s.substring(i,i+plen));
if (phash == ss)
list.add(i);
}
return list;
}
private static int gethash(String str){
int hash = 0;
for (int i = 0; i < str.length(); i++) {
int temp = ((str.charAt(i)-'a'+132)*100+36)/27;
hash += temp*temp*temp;
}
return hash;
}