We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7cdbccc commit 342e4abCopy full SHA for 342e4ab
valid-anagram/mkwkw.cpp
@@ -1 +1,37 @@
1
-//set-up
+//map: key:alphabet, value:count
2
+//if t is an anagram of s
3
+// 1. same length
4
+// 2. same content of map
5
+class Solution {
6
+public:
7
+ bool isAnagram(string s, string t) {
8
+
9
+ //1. different length -> false
10
+ if(s.length()!=t.length())
11
+ {
12
+ return false;
13
+ }
14
15
+ //2. different map -> false
16
+ map<char, int> sMap, tMap;
17
+ for(int i=0; i<s.length(); i++)
18
19
+ sMap[s[i]]++;
20
+ tMap[t[i]]++;
21
22
23
+ for(auto c : sMap)
24
25
+ if(tMap.find(c.first)==tMap.end())
26
27
28
29
+ if(tMap[c.first] != c.second)
30
31
32
33
34
35
+ return true;
36
37
+};
0 commit comments