Skip to content

Instantly share code, notes, and snippets.

@icameling
Created July 18, 2022 12:28
Show Gist options
  • Save icameling/aab739c0b4093bcbc34634ad2a542a89 to your computer and use it in GitHub Desktop.
Save icameling/aab739c0b4093bcbc34634ad2a542a89 to your computer and use it in GitHub Desktop.
#哈希表 #有效的字母异位词
class Solution {
public:
bool isAnagram(string s, string t) {
if (s.size() != t.size()) return false;
int table[26] = {0};
for (int i = 0; i < s.size(); ++i) {
table[s[i] - 'a']++;
table[t[i] - 'a']--;
}
for (int i = 0; i < 26; ++i) {
if (table[i] != 0)
return false;
}
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment