mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
26 lines
588 B
C++
26 lines
588 B
C++
#include <string>
|
|
#include <unordered_map>
|
|
|
|
class Solution {
|
|
public:
|
|
bool isAnagram(std::string s, std::string t) {
|
|
if (s.size() == t.size()) {
|
|
std::unordered_map<char, int> hmap[2];
|
|
for (int i = 0; i < s.size(); ++i) {
|
|
++hmap[0][s[i]];
|
|
++hmap[1][t[i]];
|
|
}
|
|
|
|
for (int i = (int)'a'; i <= (int)'z'; ++i) {
|
|
if (hmap[0][(char)i] != hmap[1][(char)i]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
};
|