题目中要求可以不考虑大小写,则建立一个数组,记录两个字符串中各个字符出现了多少次,都为小写字母,则减去‘a’的ASCII值,该数组0-25位,就表示了'a'-'z'
在s中不同字符每出现一次,便++
在t中不同字符每出现一次,便--
最后进行判断,如果数组中有数字不为0,则说明两字符串之间不同字符出现次数不同
class Solution {
public boolean isAnagram(String s, String t) {
int [] record = new int[26];
for(int i = 0 ; i < s.length() ; i++){
record[s.charAt(i) - 'a']++;
}
for(int i = 0 ; i < t.length(); i++){
record[t.charAt(i) - 'a']--;
}
for(int count : record){
if (count != 0){
return false;
}
}return true;
}
}