diff --git a/242. Valid Anagram.cpp b/242. Valid Anagram.cpp new file mode 100644 index 0000000..a7a28b8 --- /dev/null +++ b/242. Valid Anagram.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + bool isAnagram(string s, string t) { + if(s.length() != t.length()) return false; + + int count[26] = {0}; + + for(int i = 0; i < s.length(); i++) { + count[s[i]-'a']++; + count[t[i]-'a']--; + } + + for(int i = 0; i < 26; i++) { + if(count[i] != 0) return false; + } + + return true; + } +};