mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
Initial commit
This commit is contained in:
25
Easy/valid-anagram/solution.cpp
Normal file
25
Easy/valid-anagram/solution.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user