Valid Anagram
给两个字符串s和t, 看看是不是互为重组.
public class Solution {
public boolean isAnagram(String s, String t) {
int[] s_count = new int[256];
int[] t_count = new int[256];
for(int i = 0 ; i < s.length(); i++)
s_count[s.charAt(i)]++;
for(int i = 0 ; i < t.length(); i++)
t_count[t.charAt(i)]++;
return hash(s_count) == hash(t_count);
}
public int hash(int[] count){
int a = 3;
int b = 7;
int hash = 0;
for(int i = 0 ; i < count.length; i++){
hash += count[i]*a + b;
a*=b;
}
return hash;
}
}