Skip to content

Commit 861bfbc

Browse files
committed
valid anagram solution
1 parent d958263 commit 861bfbc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

valid-anagram/dylan-jung.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
bool isAnagram(string s, string t) {
4+
if(s.size() != t.size()) return false;
5+
unordered_map<char, int> m1;
6+
unordered_map<char, int> m2;
7+
for(char c: s) m1[c]++;
8+
for(char c: t) m2[c]++;
9+
for(auto const& item: m1) {
10+
if(m2[item.first] != item.second) return false;
11+
}
12+
return true;
13+
}
14+
};

0 commit comments

Comments
 (0)