class Solution {
public:
bool isAnagram(string s, string t) {
int hash[26] = {0};
for(int i = 0; i < s.size(); i++) {
hash[s[i] - 'a']++;
}
for(int i = 0; i < t.size(); i++) {
hash[t[i] - 'a']--;
}
int idx = 0;
while(idx < 26) {
if(hash[idx++]) return false;
}
return true;
}
};
力扣242. 有效的字母异位词
最新推荐文章于 2025-02-21 16:40:04 发布