Created
July 18, 2022 12:28
-
-
Save icameling/aab739c0b4093bcbc34634ad2a542a89 to your computer and use it in GitHub Desktop.
#哈希表 #有效的字母异位词
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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