数组也是简单的哈希表
var isAnagram = function(s, t) {
//如果两个字符串长度不一致,则返回false
if(s.length!==t.length){
return false
}
//如果长度一致
//获得字母a的编码
let a='a'.charCodeAt()
//创建数组,长度为26,值为0
let arr=new Array(26).fill(0)
//遍历字符串s
for(const i of s){
arr[i.charCodeAt()-a]++
}
//遍历字符串t
for(const x of t){
arr[x.charCodeAt()-a]--
}
//遍历数组,如果存在不为0的值,返回false
for(let h=0;h<26;h++){
if(arr[h]!=0){
return false
}
}
return true
};